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