aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2023-07-01 23:18:48 +1200
committerTom Ryder <tom@sanctum.geek.nz>2023-07-01 23:18:48 +1200
commit21e36eef243fcd42932ea1d65ccec1d34b56b931 (patch)
treeef6bd8f07c213e7f8fbcd45330b22c1c06fdd623
parentMerge branch 'release/v12.40.0' into develop (diff)
downloaddotfiles-21e36eef243fcd42932ea1d65ccec1d34b56b931.tar.gz
dotfiles-21e36eef243fcd42932ea1d65ccec1d34b56b931.zip
Add username-typing to rofi password-store script
-rw-r--r--rofi/bin/rofi_pass.sh32
1 files changed, 24 insertions, 8 deletions
diff --git a/rofi/bin/rofi_pass.sh b/rofi/bin/rofi_pass.sh
index 99b5e3e4..fb31a454 100644
--- a/rofi/bin/rofi_pass.sh
+++ b/rofi/bin/rofi_pass.sh
@@ -1,5 +1,7 @@
# Pick password from local or remote password-store with rofi's dmenu emulation
-# mode, and write it to the active X11 window.
+# mode, and write it to the active X11 window. Optionally, prefix it with the
+# username, being the last part of the slash-delimited password's name, and
+# a TAB press to move to the next field in a form.
#
self=rofi_pass
@@ -50,24 +52,38 @@ get_password() {
head -n 1
}
+# Check for --login/-l option to paste a username-password combo, not just the
+# password (defaults to the latter).
+#
+login=0
+case $1 in
+ --login|-l) login=1 ;;
+esac
+
# Apply rofi -dmenu to pick a password name. Use case-insensitive matching,
# and don't accept arbitrary input.
#
name=$(get_names | rofi -dmenu -i -no-lazy-grab -only_match -p pass) || exit
[ -n "$name" ] || exit
-# Retrieve the chosen password by name; check that we actually got something
-# back.
+# Retrieve the username for the chosen password, and then the secret itself;
+# check that we actually got more than an empty string back in both cases.
#
+username=${name##*/}
+[ -n "$username" ] || exit
password=$(get_password "$name") || exit
[ -n "$password" ] || exit
-# Have xdotool type the password, receiving it on its standard input rather
-# than its arguments, for security.
+# Have xdotool type either the username-TAB-password, or just the password;
+# receiving it on its standard input rather than its arguments, for security.
#
-printf %s "$password" |
- xdotool type --clearmodifiers --delay=0 --file - \
- || exit
+if [ "$login" -eq 1 ] ; then
+ printf '%s\t%s' \
+ "$username" "$password"
+else
+ printf '%s' \
+ "$password"
+fi | xdotool type --clearmodifiers --delay=0 --file - || exit
# Tell the user we wrote the password out, in case they're typing a password
# into a field with echo turned off.