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

color='#cc241d';
if echo "$1" | grep '^#' 2>&1; then
	color="$1"
fi

if [ -n "$WAYLAND_DISPLAY" ]; then
	dmenu="wmenu -i -l 15 -S $color"
	xdotool="ydotool type --delay 15 --file -"
elif [ -n "$DISPLAY" ]; then
	dmenu="dmenu -i -l 15 -sb $color -shb $color"
	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}/otp
rprefix=$(printf "%s" $prefix | sed 's/\//\\\//g')
password_files=$(ls "$prefix"/*.gpg | sed 's/^'${rprefix}'\///g' | sed 's/\.gpg//g')
password=$(printf "%s\n" "${password_files}" | $dmenu)

[ -n "$password" ] || exit

pass otp show otp/"$password" | { IFS= read -r pass; printf %s "$pass"; } | $xdotool