]> gitweb @ CieloNegro.org - sugar.git/blob - dot-files/_zfunc/_pass
Auto commit by The Sugar System.
[sugar.git] / dot-files / _zfunc / _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 _pass () {
13         local cmd
14         if (( CURRENT > 2)); then
15                 cmd=${words[2]}
16                 # Set the context for the subcommand.
17                 curcontext="${curcontext%:*:*}:pass-$cmd"
18                 # Narrow the range of words we are looking at to exclude `pass'
19                 (( CURRENT-- ))
20                 shift words
21                 # Run the completion for the subcommand
22                 case "${cmd}" in
23                         init)
24                                 _arguments : \
25                                         "-p[gpg-id will only be applied to this subfolder]" \
26                                         "--path[gpg-id will only be applied to this subfolder]"
27                                 _pass_complete_keys
28                                 ;;
29                         ls|list|edit)
30                                 _pass_complete_entries_with_subdirs
31                                 ;;
32                         insert)
33                                 _arguments : \
34                                         "-e[echo password to console]" \
35                                         "--echo[echo password to console]" \
36                                         "-m[multiline]" \
37                                         "--multiline[multiline]"
38                                 _pass_complete_entries_with_subdirs
39                                 ;;
40                         generate)
41                                 _arguments : \
42                                         "-n[don't include symbols in password]" \
43                                         "--no-symbols[don't include symbols in password]" \
44                                         "-c[copy password to the clipboard]" \
45                                         "--clip[copy password to the clipboard]" \
46                                         "-f[force overwrite]" \
47                                         "--force[force overwrite]" \
48                                         "-i[replace first line]" \
49                                         "--in-place[replace first line]"
50                                 _pass_complete_entries_with_subdirs
51                                 ;;
52                         cp|copy|mv|rename)
53                                 _arguments : \
54                                         "-f[force rename]" \
55                                         "--force[force rename]"
56                                         _pass_complete_entries_with_subdirs
57                                 ;;
58                         rm)
59                                 _arguments : \
60                                         "-f[force deletion]" \
61                                         "--force[force deletion]" \
62                                         "-r[recursively delete]" \
63                                         "--recursive[recursively delete]"
64                                         _pass_complete_entries_with_subdirs
65                                 ;;
66                         git)
67                                 local -a subcommands
68                                 subcommands=(
69                                         "init:Initialize git repository"
70                                         "push:Push to remote repository"
71                                         "pull:Pull from remote repository"
72                                         "config:Show git config"
73                                         "log:Show git log"
74                                         "reflog:Show git reflog"
75                                 )
76                                 _describe -t commands 'pass git' subcommands
77                                 ;;
78                         show|*)
79                                 _pass_cmd_show
80                                 ;;
81                 esac
82         else
83                 local -a subcommands
84                 subcommands=(
85                         "init:Initialize new password storage"
86                         "ls:List passwords"
87                         "find:Find password files or directories based on pattern"
88                         "grep:Search inside decrypted password files for matching pattern"
89                         "show:Decrypt and print a password"
90                         "insert:Insert a new password"
91                         "generate:Generate a new password using pwgen"
92                         "edit:Edit a password with \$EDITOR"
93                         "mv:Rename the password"
94                         "cp:Copy the password"
95                         "rm:Remove the password"
96                         "git:Call git on the password store"
97                         "version:Output version information"
98                         "help:Output help message"
99                 )
100                 _describe -t commands 'pass' subcommands
101                 _arguments : \
102                         "--version[Output version information]" \
103                         "--help[Output help message]"
104                 _pass_cmd_show
105         fi
106 }
107
108 _pass_cmd_show () {
109         _arguments : \
110                 "-c[put it on the clipboard]" \
111                 "--clip[put it on the clipboard]"
112         _pass_complete_entries
113 }
114 _pass_complete_entries_helper () {
115         local IFS=$'\n'
116         local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
117         _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##' | sort):-""}
118 }
119
120 _pass_complete_entries_with_subdirs () {
121         _pass_complete_entries_helper
122 }
123
124 _pass_complete_entries () {
125         _pass_complete_entries_helper -type f
126 }
127
128 _pass_complete_keys () {
129         local IFS=$'\n'
130         # Extract names and email addresses from gpg --list-keys
131         _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
132 }
133
134 _pass