c63fca8581352028651f6bc9c2074620c3a27352

Author
Marc Cornellà <marc.cornella@live.com>
Committer
Marc Cornellà <marc.cornella@live.com>
Date

Message

otp: add README and use clipcopy

Diff

 1diff --git a/plugins/otp/README.md b/plugins/otp/README.md
 2new file mode 100644
 3index 0000000000000000000000000000000000000000..8331fd02b4c306fc6e9dafd03be2746cacdd3f86
 4--- /dev/null
 5+++ b/plugins/otp/README.md
 6@@ -0,0 +1,22 @@
 7+# otp plugin
 8+
 9+This plugin allows you to create one-time passwords using [`oathtool`](https://www.nongnu.org/oath-toolkit/man-oathtool.html),
10+able to replace MFA devices. The oathtool key is kept in a GPG-encrypted file so the codes
11+can only be generated by a user able to decrypt it.
12+
13+To use it, add `otp` to the plugins array in your zshrc file:
14+```zsh
15+plugins=(... otp)
16+```
17+
18+Provided aliases:
19+
20+- `otp_add_device`: creates a new encrypted storage for an oathtool key and stores it
21+  on the disk. For encrypting the key, it will ask for a GPG user ID (your GPG key's
22+  email address). Then the OTP key needs to be pasted, followed by a CTRL+D character
23+  inserted on an empty line.
24+
25+- `ot`: generates a MFA code based on the given key and copies it to the clipboard 
26+  (on Linux it relies on xsel, on MacOS X it uses pbcopy instead).
27+
28+The plugin uses `$HOME/.otp` to store its internal files.
29diff --git a/plugins/otp/otp.plugin.zsh b/plugins/otp/otp.plugin.zsh
30index 4bce34fd30c0a921179646c6124d475d970cac48..8be125c93ebc6b25d0d561418c31691eeaebd97a 100644
31--- a/plugins/otp/otp.plugin.zsh
32+++ b/plugins/otp/otp.plugin.zsh
33@@ -12,32 +12,23 @@ function ot () {
34     return 1
35   fi
36 
37-  if [[ `uname` == 'Darwin' ]] then # MacOS X
38-    export COPY_CMD='pbcopy'
39-  elif command -v xsel > /dev/null 2>&1; then # Any Unix with xsel installed
40-    export COPY_CMD='xsel --clipboard --input'
41-  else
42-    COPY_CMD='true'
43-  fi
44+  COPY_CMD='true'
45 
46-  if [[ "x$1" == "x" ]]; then
47-    echo "usage: otpw <profile.name>"
48+  if [[ -z "$1" ]]; then
49+    echo "usage: $0 <profile.name>"
50     return 1
51   elif [ ! -f $OTP_HOME/$1.otp.asc ]; then
52     echo "missing profile $1, you might need to create it first using otp_add_device"
53     return 1
54   else
55     totpkey=$(gpg --decrypt $OTP_HOME/$1.otp.asc)
56-    oathtool --totp --b $totpkey | tee /dev/stderr | `echo $COPY_CMD`
57-    if [[ $COPY_CMD == 'true' ]] then
58-      echo "Note: you might consider installing xsel for clipboard integration"
59-    fi
60+    oathtool --totp --b $totpkey | tee /dev/stderr | clipcopy
61   fi
62 }
63 
64 function otp_add_device () {
65   if [[ "x$1" == "x" ]] then
66-    echo "usage: otp_add <profile.name>"
67+    echo "usage: $0 <profile.name>"
68     return 1
69   else
70     echo "Enter an email address attached to your GPG private key, then paste the secret configuration key followed by ^D"