]> git.rmz.io Git - dotfiles.git/blob - zsh/plugins/pass/_pass
add xbindkeysrc
[dotfiles.git] / zsh / plugins / pass / _pass
1 #compdef pass
2 #autoload
3
4 # Copyright (C) 2012:
5 # Johan Venant <jvenant@invicem.pro>
6 # Brian Mattern <rephorm@rephorm.com>
7 # Jason A. Donenfeld <Jason@zx2c4.com>.
8 # Santiago Borrazás <sanbor@gmail.com>
9 # All Rights Reserved.
10 # This file is licensed under the GPLv2+. Please see COPYING for more information.
11
12
13 _pass () {
14 local cmd
15 if (( CURRENT > 2)); then
16 cmd=${words[2]}
17 # Set the context for the subcommand.
18 curcontext="${curcontext%:*:*}:pass-$cmd"
19 # Narrow the range of words we are looking at to exclude `pass'
20 (( CURRENT-- ))
21 shift words
22 # Run the completion for the subcommand
23 case "${cmd}" in
24 init)
25 _arguments : \
26 "-r[re-encrypt existing passwords]" \
27 "--reencrypt[re-encrypt existing passwords]"
28 _pass_complete_keys
29 ;;
30 ls|list|edit)
31 _pass_complete_entries_with_subdirs
32 ;;
33 insert)
34 _arguments : \
35 "-e[echo password to console]" \
36 "--echo[echo password to console]" \
37 "-m[multiline]" \
38 "--multiline[multiline]"
39 _pass_complete_entries_with_subdirs
40 ;;
41 generate)
42 _arguments : \
43 "-n[don't include symbols in password]" \
44 "--no-symbols[don't include symbols in password]" \
45 "-c[copy password to the clipboard]" \
46 "--clip[copy password to the clipboard]"
47 _pass_complete_entries_with_subdirs
48 ;;
49 rm)
50 _arguments : \
51 "-f[force deletion]" \
52 "--force[force deletion]" \
53 "-r[recursively delete]" \
54 "--recursive[recursively delete]"
55 _pass_complete_entries_with_subdirs
56 ;;
57 git)
58 local -a subcommands
59 subcommands=(
60 "init:Initialize git repository"
61 "push:Push to remote repository"
62 "pull:Pull from remote repository"
63 "config:Show git config"
64 "log:Show git log"
65 "reflog:Show git reflog"
66 )
67 _describe -t commands 'pass git' subcommands
68 ;;
69 show|*)
70 _pass_cmd_show
71 ;;
72 esac
73 else
74 local -a subcommands
75 subcommands=(
76 "init:Initialize new password storage"
77 "ls:List passwords"
78 "show:Decrypt and print a password"
79 "insert:Insert a new password"
80 "generate:Generate a new password using pwgen"
81 "edit:Edit a password with \$EDITOR"
82 "rm:Remove the password"
83 "git:Call git on the password store"
84 "version:Output version information"
85 "help:Output help message"
86 )
87 _describe -t commands 'pass' subcommands
88 _arguments : \
89 "--version[Output version information]" \
90 "--help[Output help message]"
91 _pass_cmd_show
92 fi
93 }
94
95 _pass_cmd_show () {
96 _arguments : \
97 "-c[put it on the clipboard]" \
98 "--clip[put it on the clipboard]"
99 _pass_complete_entries
100 }
101 _pass_complete_entries_helper () {
102 local IFS=$'\n'
103 local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
104 _values -C 'passwords' $(find "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print | sed -e "s#${prefix}.##" -e 's#\.gpg##' | sort)
105 }
106
107 _pass_complete_entries_with_subdirs () {
108 _pass_complete_entries_helper
109 }
110
111 _pass_complete_entries () {
112 _pass_complete_entries_helper -type f
113 }
114
115 _pass_complete_keys () {
116 local IFS=$'\n'
117 # Extract names and email addresses from gpg --list-keys
118 _values 'gpg keys' $(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
119 }