-
Notifications
You must be signed in to change notification settings - Fork 0
/
complete.zsh
171 lines (146 loc) · 3.27 KB
/
complete.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#compdef pwm
# Zsh completion for the pwm command line tool.
#
# Copy this file to ~/.zsh/completions/_pwm
#
# Add it to your fpath and init completion.
#
# fpath=(~/.zsh/completions fpath)
# compinit
#
# Maybe you have to purge your compdump.
_pwm() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments \
'1: :__pwm_commands' \
'*:: :__pwm_arguments' \
'-d+[pwm database directory]:dir:_directories' \
'-h[show help]' \
'-k+[gpg key id]:key' \
'-v[show version]'
}
__pwm_force() {
# check for the -f flag in the alreday typed words
test ${words[(i)-f]} -le ${#words}
}
__pwm_exec() {
# Is pwm installed?
type pwm &>/dev/null || return 1
# Execute.
if test -z "${db}"; then
pwm $* 2>/dev/null
else
pwm -d "${db}" $* 2>/dev/null
fi
}
__pwm_keys() {
compadd $(__pwm_exec list)
}
__pwm_note_keys() {
compadd $(__pwm_exec note list)
}
__pwm_commands() {
_values 'pwm command' \
'del[delete a password]' \
'gen[generate a password]' \
'get[retrieve a password]' \
'list[list all passwords]' \
'log[print the log]' \
'note[get, set or delete a password note]' \
'set[set a password]'
}
__pwm_arguments() {
local db=${opt_args[-d]}
case "${words[1]}" in
del|gen|get|note|set)
__pwm_${words[1]} && return 0
;;
*)
return 1
esac
}
__pwm_del() {
_arguments \
':key:__pwm_keys' \
'-f[ignore nonexistent passwords]' \
'-h[show help]' \
'-m+[custom log message]:msg'
}
__pwm_gen_generators() {
_values 'pwm generator' \
'alnum[random alphanumeric characters]' \
'ascii[random printable ascii characters]' \
'hex[random hex]' \
'num[random numeric characters]'
}
__pwm_gen() {
local ret=1 keys=''
__pwm_force && keys='*:key:__pwm_keys'
_arguments \
'-c[store password in the clipboard]' \
'-f[override existing password]' \
'-g+[generator to use (default: alnum)]:generator:__pwm_gen_generators' \
'-h[show help]' \
'-l+[password length (default: 32)]:len' \
'-m+[custom log message]:msg' \
'-p[print generated password]' \
$keys
}
__pwm_get() {
_arguments \
':key:__pwm_keys' \
'-c[store password in the clipboard]' \
'-h[show help]'
}
__pwm_set() {
local keys=''
__pwm_force && keys='*:key:__pwm_keys'
_arguments \
'-c[store password in the clipboard]' \
'-f[override existing password]' \
'-h[show help]' \
'-m+[custom log message]:msg' \
'-p[print password]' \
$keys
}
__pwm_note() {
_arguments \
'1: :__pwm_note_commands' \
'*:: :__pwm_note_arguments'
}
__pwm_note_commands() {
_values 'pwm note command' \
'del[delete a note]' \
'get[retrieve a note]' \
'list[list all notes]' \
'set[set a note]'
}
__pwm_note_arguments() {
case "${words[1]}" in
del|get|set)
__pwm_note_${words[1]} && return 0
;;
*)
return 1
esac
}
__pwm_note_del() {
_arguments \
':key:__pwm_note_keys' \
'-f[ignore nonexistent notes]' \
'-h[show help]' \
'-m+[custom log message]:msg'
}
__pwm_note_get() {
_arguments \
':key:__pwm_note_keys' \
'-h[show help]'
}
__pwm_note_set() {
_arguments \
':key:__pwm_keys' \
'-f[override existing note]' \
'-h[show help]' \
'-m+[custom log message]:msg'
}