summary refs log tree commit diff
path: root/bin/passmenu
diff options
context:
space:
mode:
Diffstat (limited to 'bin/passmenu')
-rwxr-xr-xbin/passmenu57
1 files changed, 57 insertions, 0 deletions
diff --git a/bin/passmenu b/bin/passmenu
new file mode 100755
index 0000000..58001b5
--- /dev/null
+++ b/bin/passmenu
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+set -e
+[ -n "$DEBUG" ] && set -x
+
+# check requirements
+for tool in bemenu fd fzf; do
+	if ! command -v "$tool" >/dev/null; then
+		printf "%s: %s not installed but required\n" "$(basename "$0")" "$tool" >&2
+		exit 1
+	fi
+done
+
+typeit=
+if [ "$1" = "--type" ]; then
+	typeit=1
+	shift
+fi
+
+if [ "$1" = "-t" ]; then
+	_dmenu() {
+		fzf
+	}
+else
+	_dmenu() {
+		MENU_PROMPT="󰌆 pass" menu
+	}
+fi
+
+prefix=${PASSWORD_STORE_DIR-~/.password-store}
+prefix=$(readlink -f -- "${prefix}")
+password_files=$(
+	fd -e gpg . "${prefix}" | sed -e "s#${prefix}/##" -e 's#\.gpg$##'
+)
+
+password=$(printf '%s\n' "${password_files[@]}" | _dmenu "$@")
+[ -n "$password" ] || exit 1
+
+err=$(pass show "$password" 2>&1 |
+	awk 'NR==1 {system("wl-copy -o -n " $0)} /^Username:/ {system("wl-copy -n -p " $2)} {miss+=1} END{if(miss>0) print("no password found")}')
+
+# shellcheck disable=SC2181
+if [ "$?" -ne 0 ] || [ -n "$err" ]; then
+	notify-send \
+		-a passmenu \
+		-i /usr/share/icons/mdi/scalable/form-textbox-password.svg \
+		-c error \
+		'passmenu: failed :(' \
+		"<i>${err}</i>"
+	exit 1
+fi
+
+notify-send \
+	-a passmenu \
+	-i /usr/share/icons/mdi/scalable/form-textbox-password.svg \
+	'passmenu: password copied' \
+	'<i>will be removed after next paste</i>'