]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/lpass/_lpass
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / lpass / _lpass
1 #compdef lpass
2
3 _lpass() {
4     local cmd has_color has_sync has_interactive
5         if (( CURRENT > 2)); then
6         cmd=${words[2]}
7         # Set the context for the subcommand.
8         curcontext="${curcontext%:*:*}:lpass-$cmd"
9         # Narrow the range of words we are looking at to exclude `lpass'
10         (( CURRENT-- ))
11         shift words
12         # Run the completion for the subcommand
13         case "${cmd}" in
14             login)
15                 _arguments : \
16                   '--trust[Cause subsequent logins to not require multifactor authentication.]' \
17                   '--plaintext-key[Save plaintext decryption key to the hard disk]' \
18                   '--force[Do not ask on saving plaintext key]'
19                 has_color=1
20             ;;
21
22             logout)
23                 _arguments : '--force[Force confirmation]'
24                 has_color=1
25             ;;
26             show)
27                 _arguments : \
28                   '(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
29                   '(-x --expand-multi)'{-x,---expand-multi}'[Show the requested information from all of the matching sites]' \
30                   '(--all --username --password --url --notes --field= --id --name --attach=)'{--all,--username,--password,--url,--notes,--field=,--id,--name,--attach=}'[Output the specific field]' \
31                   '(--basic-regexp,--fixed-string)'{-G,--basic-regexp}'[Find a site by substring or regular expression]' \
32                   '--format=[Format output with printf-style placeholders]'
33                 _lpass_complete_uniqenames
34                 has_color=1
35                 has_sync=1
36             ;;
37
38             ls)
39                 _arguments : \
40                   '(-l --long)'{-l,--long}'[Also list the last modification time and username]' \
41                   '-u[List username]' \
42                   '-m[List modification time]' \
43                   '--format=[Format output with printf-style placeholders]'
44                                   _lpass_complete_groups
45                 has_color=1
46                 has_sync=1
47                         ;;
48             mv)
49                 _lpass_complete_uniqenames
50                 _lpass_complete_groups
51                 has_color=1
52             ;;
53             duplicate|rm)
54                 _lpass_complete_uniqenames
55                 has_color=1
56                 has_sync=1
57             ;;
58             add)
59                 _arguments : '(--username --password --url --notes --field=)'{--username,--password,--url,--notes,--field=}'[Add field]'
60                 _lpass_complete_uniqenames
61                 has_color=1
62                 has_sync=1
63                 has_interactive=1
64             ;;
65             edit)
66                 _arguments : '(--name --username --password --url --notes --field=)'{--name,--username,--password,--url,--notes,--field=}'[Update field]'
67                 _lpass_complete_uniqenames
68                 has_color=1
69                 has_sync=1
70                 has_interactive=1
71             ;;
72             generate)
73                 _arguments : \
74                   '(-c --clip)'{-c,--clip}'[Copy output to clipboard]' \
75                   '--username=[USERNAME]' \
76                   '--url=[URL]' \
77                   '--no-symbols[Do not use symbols]'
78                 has_sync=1
79             ;;
80             status)
81                _arguments : '(-q --quiet)'{-q,--quiet}'[Supress output to stdout]'
82                 has_color=1
83             ;;
84             sync)
85                 _arguments : '(-b --background)'{-b,--background}'[Run sync in background]'
86                 has_color=1
87             ;;
88             export)
89                 _arguments : '--fields=[Field list]'
90                 has_color=1
91                 has_sync=1
92             ;;
93             import)
94               if ((CURRENT < 3)); then
95                 _files
96               fi
97             ;;
98         esac
99
100         if [ -n "$has_sync" ] || [ -n "$has_color" ] || [ -n "$has_interactive" ]; then
101             local -a generic_options
102             if [ "$has_sync" -eq 1 ]; then
103                 generic_options+=('--sync=[Synchronize local cache with server: auto | now | no]')
104             fi
105             if [ "$has_color" -eq 1 ]; then
106                 generic_options+=('--color=[Color: auto | never | always]')
107             fi
108             if [ "$has_interactive" -eq 1 ]; then
109                 generic_options+=("--non-interactive[Use standard input instead of $EDITOR]")
110             fi
111             _arguments $generic_options
112         fi
113     else
114         local -a subcommands
115         subcommands=(
116           "login:Authenticate with the LastPass server and initialize a local cache"
117           "logout:Remove the local cache and stored encryption keys"
118           "passwd:Change your LastPass password"
119           "show:Display a password or selected field"
120           "ls:List names in groups in a tree structure"
121           "mv:Move the specified entry to a new group"
122           "add:Add a new entry"
123           "edit:Edit the selected field"
124           "generate:Create a randomly generated password"
125           "duplicate:Create a duplicate entry of the one specified"
126           "rm:Remove the specified entry"
127           "status:Show current login status"
128           "sync:Synchronize local cache with server"
129           "export:Dump all account information including passwords as unencrypted csv to stdout"
130           "import:Upload accounts from an unencrypted CSV file to the server"
131           "share:Manipulate shared folders (only enterprise or premium user)"
132         )
133         _describe -t commands 'lpass' subcommands
134         _arguments : \
135           '(-h --help)'{-h,--help}'[show help]' \
136           '(-v --version)'{-v,--version}'[show version]'
137
138     fi
139 }
140
141 _lpass_complete_uniqenames(){
142   local -a entries
143   while read i;  do
144     if [ -n "$i" ]; then
145       entries+=("$i")
146     fi
147   done < <(lpass ls --sync auto --format "%an" --color=never)
148   compadd -a entries
149 }
150
151
152 _lpass_complete_groups() {
153   local -a entries
154   while read i;  do
155     if [ -n "$i" ]; then
156       entries+=("$i")
157     fi
158   done < <(lpass ls --sync auto --format "%aN" --color=never | grep -E "\/$")
159   compadd -a entries
160 }
161
162 _lpass
163 # Local Variables:
164 # mode: Shell-Script
165 # sh-indentation: 2
166 # indent-tabs-mode: nil
167 # sh-basic-offset: 2
168 # End:
169 # vim: ft=zsh sw=2 ts=2 et