diff options
author | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
---|---|---|
committer | Aditya <bluenerd@protonmail.com> | 2023-02-27 20:04:56 +0530 |
commit | edc449275b6c04445f58b108ca0937a87c1e8430 (patch) | |
tree | 9fd484d58145b616f29a78857cc0b1c8b1c18f05 /oh-my-zsh/plugins/otp/otp.plugin.zsh | |
parent | 6f5424ca96c4221ef433f545642669e9c104d0ed (diff) |
add zsh
Diffstat (limited to 'oh-my-zsh/plugins/otp/otp.plugin.zsh')
-rw-r--r-- | oh-my-zsh/plugins/otp/otp.plugin.zsh | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/oh-my-zsh/plugins/otp/otp.plugin.zsh b/oh-my-zsh/plugins/otp/otp.plugin.zsh new file mode 100644 index 0000000..8be125c --- /dev/null +++ b/oh-my-zsh/plugins/otp/otp.plugin.zsh @@ -0,0 +1,45 @@ +export OTP_HOME=~/.otp +mkdir -p $OTP_HOME + +function ot () { + if ! command -v oathtool > /dev/null 2>&1; then + echo "Note: you need to install oathtool or oath-toolkit, depending on your OS or distribution." + return 1 + fi + + if ! command -v gpg > /dev/null 2>&1; then + echo "Note: you need to install gpg and create an ID using 'gpg --gen-key', unless you have one already." + return 1 + fi + + COPY_CMD='true' + + if [[ -z "$1" ]]; then + echo "usage: $0 <profile.name>" + return 1 + elif [ ! -f $OTP_HOME/$1.otp.asc ]; then + echo "missing profile $1, you might need to create it first using otp_add_device" + return 1 + else + totpkey=$(gpg --decrypt $OTP_HOME/$1.otp.asc) + oathtool --totp --b $totpkey | tee /dev/stderr | clipcopy + fi +} + +function otp_add_device () { + if [[ "x$1" == "x" ]] then + echo "usage: $0 <profile.name>" + return 1 + else + echo "Enter an email address attached to your GPG private key, then paste the secret configuration key followed by ^D" + + rm -f $OTP_HOME/$1.otp.asc + gpg --armor --encrypt --output $OTP_HOME/$1.otp.asc /dev/stdin + fi +} + +function otp_devices () { + reply=($(find $OTP_HOME -name \*.otp.asc | xargs basename -s .otp.asc)) +} + +compctl -K otp_devices ot |