summaryrefslogtreecommitdiff
path: root/otpmenu
blob: 7c2ff43992168fef3862b64b6fab35aa53e353eb (plain) (blame)
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
#!/usr/bin/env bash

shopt -s nullglob globstar

typeit=0
if [[ $1 == "--type" ]]; then
	typeit=1
	shift
fi

if [[ -n $WAYLAND_DISPLAY ]]; then
	menu="fuzzel -d"
	typetool="wtype -"
else
	echo "Error: No Wayland display detected" >&2
	exit 1
fi

prefix="$HOME"/.local/share/password-store
password_files=( "$prefix"/**/otp.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )

password=$(printf '%s\n' "${password_files[@]}" | $menu "$@")

[[ -n $password ]] || exit

if [[ $typeit -eq 0 ]]; then
	pass otp show -c "$password" 2>/dev/null
else
	pass otp show "$password" | { IFS= read -r pass; printf %s "$pass"; } | $typetool
fi