diff options
author | Hsieh Chin Fan <typebrook@gmail.com> | 2021-02-21 14:18:05 +0800 |
---|---|---|
committer | Hsieh Chin Fan <typebrook@gmail.com> | 2021-02-21 14:18:05 +0800 |
commit | c757b6df6fbd2e8c62a2e2dc7165314f403c2110 (patch) | |
tree | df9ae312c2d0235d32dd94c83d7f1abc5af21da3 | |
parent | 106d497be9ce6376c6c2849d75aaed13681980af (diff) |
update
-rwxr-xr-x | tools/init/load-settings.sh | 1 | ||||
-rw-r--r-- | zsh/pass.zsh-completion | 144 |
2 files changed, 145 insertions, 0 deletions
diff --git a/tools/init/load-settings.sh b/tools/init/load-settings.sh index b46169d..73db314 100755 --- a/tools/init/load-settings.sh +++ b/tools/init/load-settings.sh | |||
@@ -1,5 +1,6 @@ | |||
1 | if [[ $0 == 'zsh' ]]; then | 1 | if [[ $0 == 'zsh' ]]; then |
2 | setopt extended_glob | 2 | setopt extended_glob |
3 | fpath=($SETTING_DIR/zsh $fpath) | ||
3 | elif [[ $0 == 'bash' ]]; then | 4 | elif [[ $0 == 'bash' ]]; then |
4 | shopt -s extglob | 5 | shopt -s extglob |
5 | fi | 6 | fi |
diff --git a/zsh/pass.zsh-completion b/zsh/pass.zsh-completion new file mode 100644 index 0000000..27ce15a --- /dev/null +++ b/zsh/pass.zsh-completion | |||
@@ -0,0 +1,144 @@ | |||
1 | #compdef pass | ||
2 | #autoload | ||
3 | |||
4 | # Copyright (C) 2012 - 2014: | ||
5 | # Johan Venant <jvenant@invicem.pro> | ||
6 | # Brian Mattern <rephorm@rephorm.com> | ||
7 | # Jason A. Donenfeld <Jason@zx2c4.com>. | ||
8 | # All Rights Reserved. | ||
9 | # This file is licensed under the GPLv2+. Please see COPYING for more information. | ||
10 | |||
11 | |||
12 | # If you use multiple repositories, you can configure completion like this: | ||
13 | # | ||
14 | # compdef _pass workpass | ||
15 | # zstyle ':completion::complete:workpass::' prefix "$HOME/work/pass" | ||
16 | # workpass() { | ||
17 | # PASSWORD_STORE_DIR=$HOME/work/pass pass $@ | ||
18 | # } | ||
19 | |||
20 | |||
21 | _pass () { | ||
22 | local cmd | ||
23 | if (( CURRENT > 2)); then | ||
24 | cmd=${words[2]} | ||
25 | # Set the context for the subcommand. | ||
26 | curcontext="${curcontext%:*:*}:pass-$cmd" | ||
27 | # Narrow the range of words we are looking at to exclude `pass' | ||
28 | (( CURRENT-- )) | ||
29 | shift words | ||
30 | # Run the completion for the subcommand | ||
31 | case "${cmd}" in | ||
32 | init) | ||
33 | _arguments : \ | ||
34 | "-p[gpg-id will only be applied to this subfolder]" \ | ||
35 | "--path[gpg-id will only be applied to this subfolder]" | ||
36 | _pass_complete_keys | ||
37 | ;; | ||
38 | ls|list|edit) | ||
39 | _pass_complete_entries_with_subdirs | ||
40 | ;; | ||
41 | insert) | ||
42 | _arguments : \ | ||
43 | "-e[echo password to console]" \ | ||
44 | "--echo[echo password to console]" \ | ||
45 | "-m[multiline]" \ | ||
46 | "--multiline[multiline]" | ||
47 | _pass_complete_entries_with_subdirs | ||
48 | ;; | ||
49 | generate) | ||
50 | _arguments : \ | ||
51 | "-n[don't include symbols in password]" \ | ||
52 | "--no-symbols[don't include symbols in password]" \ | ||
53 | "-c[copy password to the clipboard]" \ | ||
54 | "--clip[copy password to the clipboard]" \ | ||
55 | "-f[force overwrite]" \ | ||
56 | "--force[force overwrite]" \ | ||
57 | "-i[replace first line]" \ | ||
58 | "--in-place[replace first line]" | ||
59 | _pass_complete_entries_with_subdirs | ||
60 | ;; | ||
61 | cp|copy|mv|rename) | ||
62 | _arguments : \ | ||
63 | "-f[force rename]" \ | ||
64 | "--force[force rename]" | ||
65 | _pass_complete_entries_with_subdirs | ||
66 | ;; | ||
67 | rm) | ||
68 | _arguments : \ | ||
69 | "-f[force deletion]" \ | ||
70 | "--force[force deletion]" \ | ||
71 | "-r[recursively delete]" \ | ||
72 | "--recursive[recursively delete]" | ||
73 | _pass_complete_entries_with_subdirs | ||
74 | ;; | ||
75 | git) | ||
76 | local -a subcommands | ||
77 | subcommands=( | ||
78 | "init:Initialize git repository" | ||
79 | "push:Push to remote repository" | ||
80 | "pull:Pull from remote repository" | ||
81 | "config:Show git config" | ||
82 | "log:Show git log" | ||
83 | "reflog:Show git reflog" | ||
84 | ) | ||
85 | _describe -t commands 'pass git' subcommands | ||
86 | ;; | ||
87 | show|*) | ||
88 | _pass_cmd_show | ||
89 | ;; | ||
90 | esac | ||
91 | else | ||
92 | local -a subcommands | ||
93 | subcommands=( | ||
94 | "init:Initialize new password storage" | ||
95 | "ls:List passwords" | ||
96 | "find:Find password files or directories based on pattern" | ||
97 | "grep:Search inside decrypted password files for matching pattern" | ||
98 | "show:Decrypt and print a password" | ||
99 | "insert:Insert a new password" | ||
100 | "generate:Generate a new password using pwgen" | ||
101 | "edit:Edit a password with \$EDITOR" | ||
102 | "mv:Rename the password" | ||
103 | "cp:Copy the password" | ||
104 | "rm:Remove the password" | ||
105 | "git:Call git on the password store" | ||
106 | "version:Output version information" | ||
107 | "help:Output help message" | ||
108 | ) | ||
109 | _describe -t commands 'pass' subcommands | ||
110 | _arguments : \ | ||
111 | "--version[Output version information]" \ | ||
112 | "--help[Output help message]" | ||
113 | _pass_cmd_show | ||
114 | fi | ||
115 | } | ||
116 | |||
117 | _pass_cmd_show () { | ||
118 | _arguments : \ | ||
119 | "-c[put it on the clipboard]" \ | ||
120 | "--clip[put it on the clipboard]" | ||
121 | _pass_complete_entries | ||
122 | } | ||
123 | _pass_complete_entries_helper () { | ||
124 | local IFS=$'\n' | ||
125 | local prefix | ||
126 | zstyle -s ":completion:${curcontext}:" prefix prefix || prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}" | ||
127 | _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#\\#\\\\#' | sort):-""} | ||
128 | } | ||
129 | |||
130 | _pass_complete_entries_with_subdirs () { | ||
131 | _pass_complete_entries_helper | ||
132 | } | ||
133 | |||
134 | _pass_complete_entries () { | ||
135 | _pass_complete_entries_helper -type f | ||
136 | } | ||
137 | |||
138 | _pass_complete_keys () { | ||
139 | local IFS=$'\n' | ||
140 | # Extract names and email addresses from gpg --list-keys | ||
141 | _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d') | ||
142 | } | ||
143 | |||
144 | _pass | ||