summaryrefslogtreecommitdiff
path: root/passmenu.sh
diff options
context:
space:
mode:
Diffstat (limited to 'passmenu.sh')
-rwxr-xr-xpassmenu.sh134
1 files changed, 134 insertions, 0 deletions
diff --git a/passmenu.sh b/passmenu.sh
new file mode 100755
index 0000000..9b6ad22
--- /dev/null
+++ b/passmenu.sh
@@ -0,0 +1,134 @@
+#!/bin/sh
+
+# !!!! UPDATE WITH ROFI GOODNESS
+
+###
+# passmenu - dmenu interface for password-store
+#
+# The popular, commonly used script for this purpose is available at
+# <https://git.zx2c4.com/password-store/tree/contrib/dmenu/passmenu>
+# (as of 2019-05-20).
+# However, that script has been written in bash. This is my own, pure sh
+# implementation. I believe it is slower and a lot less efficient. Nevertheless,
+# it just works(TM). It is also tailored to my own liking.
+#
+# The script requires the following binaries in PATH to work:
+# - pass (password-store, obviously)
+# - dmenu (also rather obvious)
+# - xsel (for the ability to copy the username only)
+#
+# The script has a manual included, but for the sake of redundancy, the options
+# are also listed below. It accepts all options dmenu accepts and uses them as
+# expected.
+#
+# SYNOPSIS: passmenu [-hu] [dmenu options]
+# -h, --help print usage
+# -u, --username copy the username, not the password
+#
+# bertalanp99@ 2019-05-20
+###
+
+#################
+### FUNCTIONS ###
+#################
+
+usage()
+{
+ printf 'usage: passmenu [-hu]'
+}
+
+
+#################
+### VARIABLES ###
+#################
+
+prefix=${PASSWORD_STORE_DIR-$HOME/.password-store/}
+
+
+##############
+### SCRIPT ###
+##############
+
+### CHECK FOR BINARIES IN PATH ###
+
+for binary in pass rofi xsel
+do
+ if ! command -v $binary >/dev/null 2>&1
+ then
+ echo "this script needs '$binary' in PATH to work"
+ exit 1
+ fi
+done
+
+### PARSE OPTIONS ###
+
+needuser=0
+dmenuoptions=
+while [ -n "$1" ]
+do
+ case $1 in
+ -b|-f|-i|-v)
+ dmenuoptions="$dmenuoptions $1"
+ ;;
+
+ -l|-m|-p|-fn|-nb|-nf|-sb|-sf|-w)
+ dmenuoptions="$dmenuoptions $1 $2"
+ shift
+ ;;
+
+ -c)
+ cli=1
+ ;;
+
+ -h)
+ usage
+ exit 0
+ ;;
+
+ -u)
+ needuser=1
+ ;;
+
+ *)
+ echo "unknown option -- $1"
+ usage
+ exit 1
+ ;;
+ esac
+ shift
+done
+
+### MAIN ###
+
+
+if [ -n "$cli" ]; then
+ password="`find "$prefix" -name '*.gpg' \
+ | sed "s|$prefix\(.*\).gpg|\1|" \
+ | fzf`"
+ pass show "$password"
+ exit
+fi
+
+password="$(\
+ find "$prefix" -name '*.gpg' \
+ | sed "s|${prefix}\(.*\).gpg|\1|" \
+ | rofi -dmenu $dmenuoptions)"
+
+if [ $needuser -eq 0 ]
+then
+ pw="$(pass show "$password" 2>/dev/null \
+ | sed 1q \
+ | tr -d '\n')"
+ xdotool type --delay 4 "$pw"
+else
+ login="$(pass show "$password" 2>/dev/null \
+ | awk '/login:/{print $2}' \
+ | tr -d '\n')"
+ pw="$(pass show "$password" 2>/dev/null \
+ | sed 1q \
+ | tr -d '\n')"
+ xdotool type --delay 4 "$login"
+ xdotool type --delay 4 "\t"
+ xdotool type --delay 4 "$pass"
+ xdotool type --delay 4 " "
+fi