]> git.armaanb.net Git - bin.git/commitdiff
passmenu: add script
authorArmaan Bhojwani <me@armaanb.net>
Fri, 7 May 2021 15:09:53 +0000 (11:09 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Fri, 7 May 2021 15:13:27 +0000 (11:13 -0400)
passmenu [new file with mode: 0755]

diff --git a/passmenu b/passmenu
new file mode 100755 (executable)
index 0000000..ed5748a
--- /dev/null
+++ b/passmenu
@@ -0,0 +1,23 @@
+#!/usr/bin/env sh
+# A POSIX compliant reimplementation of passmenu. Derived from:
+# https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu
+
+typeit=0
+if [ "$1" = "--type" ]; then
+       typeit=1
+       shift
+fi
+
+prefix=${PASSWORD_STORE_DIR-~/.password-store}
+password=$(find $prefix -name '*.gpg' | awk -v prefix="$prefix" \
+       '{len = length(prefix) + 2; print substr($0, len, length($0) - len - 3)}' \
+       | dmenu "$@")
+
+[ -n $password ] || exit
+
+if [ $typeit -eq 0 ]; then
+       pass show -c "$password" 2>/dev/null
+else
+       pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } |
+               xdotool type --clearmodifiers --file -
+fi