otp.plugin.zsh
1239 bytes
1export OTP_HOME=~/.otp
2mkdir -p $OTP_HOME
3
4function ot () {
5 if ! command -v oathtool > /dev/null 2>&1; then
6 echo "Note: you need to install oathtool or oath-toolkit, depending on your OS or distribution."
7 return 1
8 fi
9
10 if ! command -v gpg > /dev/null 2>&1; then
11 echo "Note: you need to install gpg and create an ID using 'gpg --gen-key', unless you have one already."
12 return 1
13 fi
14
15 COPY_CMD='true'
16
17 if [[ -z "$1" ]]; then
18 echo "usage: $0 <profile.name>"
19 return 1
20 elif [ ! -f $OTP_HOME/$1.otp.asc ]; then
21 echo "missing profile $1, you might need to create it first using otp_add_device"
22 return 1
23 else
24 totpkey=$(gpg --decrypt $OTP_HOME/$1.otp.asc)
25 oathtool --totp --b $totpkey | tee /dev/stderr | clipcopy
26 fi
27}
28
29function otp_add_device () {
30 if [[ "x$1" == "x" ]] then
31 echo "usage: $0 <profile.name>"
32 return 1
33 else
34 echo "Enter an email address attached to your GPG private key, then paste the secret configuration key followed by ^D"
35
36 rm -f $OTP_HOME/$1.otp.asc
37 gpg --armor --encrypt --output $OTP_HOME/$1.otp.asc /dev/stdin
38 fi
39}
40
41function otp_devices () {
42 reply=($(find $OTP_HOME -name \*.otp.asc | xargs basename -s .otp.asc))
43}
44
45compctl -K otp_devices ot