otp: added a plugin for oathtool one-time passwords (#3862)
Diff
1diff --git a/plugins/otp/otp.plugin.zsh b/plugins/otp/otp.plugin.zsh
2new file mode 100644
3index 0000000000000000000000000000000000000000..4bce34fd30c0a921179646c6124d475d970cac48
4--- /dev/null
5+++ b/plugins/otp/otp.plugin.zsh
6@@ -0,0 +1,54 @@
7+export OTP_HOME=~/.otp
8+mkdir -p $OTP_HOME
9+
10+function ot () {
11+ if ! command -v oathtool > /dev/null 2>&1; then
12+ echo "Note: you need to install oathtool or oath-toolkit, depending on your OS or distribution."
13+ return 1
14+ fi
15+
16+ if ! command -v gpg > /dev/null 2>&1; then
17+ echo "Note: you need to install gpg and create an ID using 'gpg --gen-key', unless you have one already."
18+ return 1
19+ fi
20+
21+ if [[ `uname` == 'Darwin' ]] then # MacOS X
22+ export COPY_CMD='pbcopy'
23+ elif command -v xsel > /dev/null 2>&1; then # Any Unix with xsel installed
24+ export COPY_CMD='xsel --clipboard --input'
25+ else
26+ COPY_CMD='true'
27+ fi
28+
29+ if [[ "x$1" == "x" ]]; then
30+ echo "usage: otpw <profile.name>"
31+ return 1
32+ elif [ ! -f $OTP_HOME/$1.otp.asc ]; then
33+ echo "missing profile $1, you might need to create it first using otp_add_device"
34+ return 1
35+ else
36+ totpkey=$(gpg --decrypt $OTP_HOME/$1.otp.asc)
37+ oathtool --totp --b $totpkey | tee /dev/stderr | `echo $COPY_CMD`
38+ if [[ $COPY_CMD == 'true' ]] then
39+ echo "Note: you might consider installing xsel for clipboard integration"
40+ fi
41+ fi
42+}
43+
44+function otp_add_device () {
45+ if [[ "x$1" == "x" ]] then
46+ echo "usage: otp_add <profile.name>"
47+ return 1
48+ else
49+ echo "Enter an email address attached to your GPG private key, then paste the secret configuration key followed by ^D"
50+
51+ rm -f $OTP_HOME/$1.otp.asc
52+ gpg --armor --encrypt --output $OTP_HOME/$1.otp.asc /dev/stdin
53+ fi
54+}
55+
56+function otp_devices () {
57+ reply=($(find $OTP_HOME -name \*.otp.asc | xargs basename -s .otp.asc))
58+}
59+
60+compctl -K otp_devices ot