m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/contrib/pass.zsh-completion
blob: bcb2f98d87753b5ae45f2d0a6ca09c47c2e60524 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#compdef pass

# Copyright (C) 2012 Johan Venant <jvenant@invicem.pro> and
# Brian Mattern <rephorm@rephorm.com>. All Rights Reserved.
# This file is licensed under the GPLv2+. Please see COPYING for more information.

_pass () {
	local cmd
	if (( CURRENT > 2)); then
		cmd=${words[2]}
		# Set the context for the subcommand.
		curcontext="${curcontext%:*:*}:pass-$cmd"
		# Narrow the range of words we are looking at to exclude `pass'
		(( CURRENT-- ))
		shift words
		# Run the completion for the subcommand
		case "${cmd}" in
			init)
				_arguments : \
					"-r[re-encrypt existing passwords]" \
					"--reencrypt[re-encrypt existing passwords]"
				_pass_complete_keys
				;;
			ls|list|edit)
				_pass_complete_entries_with_subdirs
				;;
			insert)
				_arguments : \
					"-n[no console output]" \
					"--no-echo[no console output]" \
					"-m[multiline]" \
					"--multiline[multiline]"
				_pass_complete_entries_with_subdirs
				;;
			generate)
				_arguments : \
					"-n[don't include symbols in password]" \
					"--no-symbols[don't include symbols in password]" \
					"-c[copy password to the clipboard]" \
					"--clip[copy password to the clipboard]"
				_pass_complete_entries_with_subdirs
				;;
			rm)
				_arguments : \
					"-f[force deletion]" \
					"--force[force deletion]" \
					"-r[recursively delete]" \
					"--recursive[recursively delete]"
					_pass_complete_entries_with_subdirs
				;;
			git)
				_values 'subcommands' \
					"init[Initialize git repository]" \
					"push[Push to remote repository]" \
					"pull[Pull from remote repository]" \
					"config[Show git config]" \
					"log[Show git log]" \
					"reflog[Show git reflog]"
				;;
			show|*)
				_pass_cmd_show
				;;
		esac
	else
		_values 'command' \
			"init[Initialize new password storage]" \
			"ls[List passwords]" \
			"show[Decrypt and print a password]" \
			"insert[Insert a new password]" \
			"generate[Generate a new password using pwgen]" \
			"edit[Edit a password with \$EDITOR]" \
			"rm[Remove the password]" \
			"git[Call git on the password store]" \
			"version[Output version information]" \
			"help[Output help message]"
		_arguments : \
			"--version[Output version information]" \
			"--help[Output help message]"
		_pass_cmd_show
	fi
}

_pass_cmd_show () {
	_arguments : \
		"-c[put it on the clipboard]" \
		"--clip[put it on the clipboard]"
	_pass_complete_entries
}
_pass_complete_entries_helper () {
	local IFS=$'\n'
	local prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
	_values -C 'passwords' $(find "$prefix" \( -name .git -o -name .gpg-id \) -prune -o $@ -print | sed -e "s#${prefix}.##" -e 's#\.gpg##' | sort)
}

_pass_complete_entries_with_subdirs () {
	_pass_complete_entries_helper
}

_pass_complete_entries () {
	_pass_complete_entries_helper -type f
}

_pass_complete_keys () {
	local IFS=$'\n'
	# Extract names and email addresses from gpg --list-keys
	_values 'gpg keys' $(gpg --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')
}