Hi!

I've just recently started using pass and more specifically passmenu, and am 
very pleased with it :-)


The main feature I found that was immediately missing when switching over from 
keepassx, is the ability to autotype a username/password combination. I read 
through the mailing list archives and found this feature was already attempted 
here: 
https://lists.zx2c4.com/pipermail/password-store/2015-December/001834.html<https://lists.zx2c4.com/pipermail/password-store/2015-December/001834.html>


It doesn't seem like there was any response to this, but arbitrarily taking the 
second line doesn't seem ideal to me. I think my implementation is an 
improvement, because it leverages the suggested file format of "key: value" 
pairs after the first line.


In the included patch you will see that I've just added a --userfield flag 
which can be used as follows:

passmenu --type --userfield username [dmenu arguments...]


This corresponds to files which look like:

passw0rd

username: matt.snider


I personally use this by binding $mod+p to the regular passmenu invocation, and 
$mod+Shift+p to the invocation using --type and --userfield. This has been 
working very well for me.


Please let me know what you think and if you have some feedback.


Best,

Matt


From bb6a5117f01996c3960c4e1fa40a5fe5b22439e0 Mon Sep 17 00:00:00 2001
From: Matt Snider <[email protected]>
Date: Sun, 23 Jul 2017 15:33:47 +0200
Subject: [PATCH] Improve passmenu by also supporting typing usernames

---
 contrib/dmenu/README.md | 15 +++++++++++++--
 contrib/dmenu/passmenu  | 16 +++++++++++-----
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/contrib/dmenu/README.md b/contrib/dmenu/README.md
index 9d54fb4..ed7bb75 100644
--- a/contrib/dmenu/README.md
+++ b/contrib/dmenu/README.md
@@ -2,11 +2,22 @@
 password manager. This design allows you to quickly copy a password to the
 clipboard without having to open up a terminal window if you don't already have
 one open. If `--type` is specified, the password is typed using [xdotool][]
-instead of copied to the clipboard.
+instead of being copied to the clipboard. To type both the username and password,
+additionally specify `--userfield fieldname`, where its argument corresponds to
+the username you use in your password files.
 
 # Usage
 
-    passmenu [--type] [dmenu arguments...]
+    passmenu [--type [--userfield fieldname]] [dmenu arguments...]
+
+## With --userfield
+
+    passmenu --type --userfield Username [dmenu arguments...]
+
+```
+passw0rd
+Username: john.doe
+```
 
 [dmenu]: http://tools.suckless.org/dmenu/
 [xdotool]: http://www.semicomplete.com/projects/xdotool/
diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 7a9c517..b878222 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -2,11 +2,14 @@
 
 shopt -s nullglob globstar
 
-typeit=0
-if [[ $1 == "--type" ]]; then
-	typeit=1
-	shift
-fi
+typeit=0 hasuserfield=0
+opts="$(getopt -l typeit,userfield: -n 'passmenu' -- '$@')"
+
+while true; do case $1 in
+	--type) typeit=1; shift ;;
+	--userfield) hasuserfield=1; userfield="${2:-1}"; shift 2 ;;
+	*) break ;;
+esac done
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
@@ -19,6 +22,9 @@ password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
 
 if [[ $typeit -eq 0 ]]; then
 	pass show -c "$password" 2>/dev/null
+elif [[ $hasuserfield -ne 0 ]]; then
+	pass show "$password" | { read -r -d '\n' pass rest; echo "$rest" | sed -n "s/${userfield}:\s\?\(.*\)/\1/p" | xargs -i printf  '%s\t%s\n' {} "$pass"; }  |
+		xdotool type --clearmodifiers --file -
 else
 	pass show "$password" | { read -r pass; printf %s "$pass"; } |
 		xdotool type --clearmodifiers --file -
-- 
2.13.3

_______________________________________________
Password-Store mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to