]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/pass/_pass
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / pass / _pass
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#\\#\\\\#g' -e 's#:#\\:#g' | 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