summaryrefslogtreecommitdiff
path: root/bin/menuscripts/mpass
blob: 5a09623ee304d2ab15a4fa0f03938d6cfaa408f4 (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
#!/usr/bin/env sh
store="${PASSWORD_STORE_DIR:-$HOME/.password-store}"

# list passwords, group directories first
list_pswds()
{
	find "$1" \
		-maxdepth 1 -mindepth 1 \
		-not -name '.*' -type d -printf "%y\t%f\n" -o \
		-not -name '.*' -not -type d -printf "%y\t%f\n" |
		sort -k1 -k2 |
		cut -f 2 | sed 's/\.gpg$//'
}

file="$1"
while [ -d "$store/$file" ]
do
	choice="$(list_pswds "$store/$file" | commander -c)"
	[ "$choice" ] || exit 1
	[ -z "$file" ] && file="$choice" || file="$file/$choice"
done
[ "$file" ] || exit 1

pass show -c "$file" || exit 1
herbe "_mpass" "*$file"

[ "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null && # on wayland and cliphist is running
	cliphist list | head -n 1 | cliphist delete