summaryrefslogtreecommitdiffstats
path: root/.local/bin/dmpass
blob: d5b04941d4dcee5dc0ad32c5483fe8ac83b77f8b (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
#!/bin/sh

full=0
color='#cc241d';
if [ "$1" = "--full" ]; then
	full=1
	if echo "$2" | grep '^#' 2>&1; then
		color="$2"
	fi
elif echo "$1" | grep '^#' 2>&1; then
	color="$1"
fi


if [ -n "$WAYLAND_DISPLAY" ]; then
	dmenu=dmenu-wl
	xdotool="ydotool type --file -"
elif [ -n "$DISPLAY" ]; then
	dmenu=dmenu
	xdotool="xdotool type --delay 15 --clearmodifiers --file -"
else
	echo "Error: No Wayland or X11 display detected" >&2
	exit 1
fi

prefix=${PASSWORD_STORE_DIR-~/.local/share/pass}
rprefix=$(printf "%s" $prefix | sed 's/\//\\\//g')
password_files=$(ls "$prefix"/*.gpg "$prefix"/*/*.gpg | sed 's/^'${rprefix}'\///g' | sed 's/\.gpg//g')
password=$(printf "%s\n" "${password_files}" | "$dmenu" -i -l 15 -sb "$color" -shb "$color")

[ -n "$password" ] || exit

p="$(pass show "$password")"

if [ $full -eq 1 ]; then
	id=$(printf "%s" "$password" | sed 's/.*___//')
	printf "%s\n" $id | { IFS= read -r pass; printf %s "$id"; } | $xdotool
	xdotool key Tab
	printf "%s\n" "$p" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool
	xdotool key Return
	exit
fi

printf "%s\n" "$p" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool