| 1 | #compdef sp |
| 2 | #autoload |
| 3 | |
| 4 | _sp () { |
| 5 | local cmd |
| 6 | if (( CURRENT > 2)); then |
| 7 | cmd=${words[2]} |
| 8 | curcontext="${curcontext%:*:*}:pass-$cmd" |
| 9 | (( CURRENT-- )) |
| 10 | shift words |
| 11 | case "${cmd}" in |
| 12 | -i) |
| 13 | _sp_complete_keys |
| 14 | ;; |
| 15 | -i|-y|-d|-a|-e|-o|-O) |
| 16 | _sp_complete_entries_helper |
| 17 | ;; |
| 18 | -g) |
| 19 | local -a subcommands |
| 20 | subcommands=( |
| 21 | "secure:英数字+記号文字(デフォルト)" |
| 22 | "risk:英数字のみ(不安)" |
| 23 | ) |
| 24 | ;; |
| 25 | -s) |
| 26 | _sp_cmd_show |
| 27 | ;; |
| 28 | esac |
| 29 | else |
| 30 | local -a subcommands |
| 31 | subcommands=( |
| 32 | "-a:パスワードを追加" |
| 33 | "-b:漏洩されたパスワードを確認(インターネット接続が必須)" |
| 34 | "-c:パスワードの長さ、強さ、や服数度を確認する。length=パスワードの長さの確認、strength=パスワードの強さの確認、duplicate=服数パスワードが同じかどうか確認、all=上記の全部の確認" |
| 35 | "-d:パスワードを削除" |
| 36 | "-e:パスワードを変更" |
| 37 | "-g:希望文字数でパスワードをランダムに作成する。デフォルトな長さは64文字です。secure=英数字+記号文字(デフォルト)を使用、risk=英数字のみ(不安)を使用" |
| 38 | "-i:GPGと使ってパスワードストレージを初期設定" |
| 39 | "-l:パスワード一覧を表示" |
| 40 | "-o:ワンタイムパスワード(TOTP)を表示" |
| 41 | "-O:ワンタイムパスワード(TOTP)をコピー。デフォルトは30秒です。" |
| 42 | "-s:パスワードを表示" |
| 43 | "-v:バージョンを表示" |
| 44 | "-y:パスワードを表示せずクリップボードにコピーする(Xorgのみ)。デフォルトは45秒です。" |
| 45 | ) |
| 46 | _sp_cmd_show |
| 47 | fi |
| 48 | } |
| 49 | |
| 50 | _sp_cmd_show () { |
| 51 | _sp_complete_entries |
| 52 | } |
| 53 | |
| 54 | _sp_complete_entries() { |
| 55 | _sp_complete_entries_helper -type f |
| 56 | } |
| 57 | |
| 58 | _sp_complete_entries_helper () { |
| 59 | local IFS=$'\n' |
| 60 | local prefix |
| 61 | zstyle -s ":completion:${curcontext}:" prefix prefix || prefix="${SP_DIR:-$HOME/.local/share/sp}" |
| 62 | _values -C 'passwords' ${$(find -L "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print 2>/dev/null | sed -e "s#${prefix}/\{0,1\}##" -e 's#\.gpg##' -e 's#\\#\\\\#g' -e 's#:#\\:#g' | sort):-""} |
| 63 | } |
| 64 | |
| 65 | _sp_complete_keys () { |
| 66 | local IFS=$'\n' |
| 67 | _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d') |
| 68 | } |
| 69 | |
| 70 | _sp |