> In some cases it may be better to share a script that calls pass, rather than 
> try to patch pass itself. This way, everyone may customize it for their own 
> repository layout and unique use case.

If I understand correctly, this is about choosing line2 == username.
TBF, this is a patch to passmenu and not pass, and passmenu already
presumes line1 == pwd, even though pass's manpage shows an example
(“awesome”) multiline password. It does seem reasonable to extend this
logic the way Alexander does.

> The quite amazing rofi-pass does this already with a sensible format: 
> https://github.com/carnager/rofi-pass

Thanks, interesting info. Passmenu still makes sense for dmenu users though.

I'm inserting two proposed patches: my take on Alexander's version but
in a --type-and-copy scheme (I took the liberty of replacing the
--type-fully scheme rather than just extending it, because IMO it
replaces the need for it), followed by a proposal to improve
readability of the passmenu script in general.
From 47a26d3ccba1399143b1997bfac25c5866930a5c Mon Sep 17 00:00:00 2001
From: John Gliksberg <[email protected]>
Date: Tue, 9 Jul 2019 11:36:57 +0200
Subject: [PATCH 2/2] dmenu: Improve readability

Replace ``IFS= read'' bashism with explicit ``tr -d'' call

Use case block for argument parsing

Use case block for action choice
---
 contrib/dmenu/passmenu | 45 +++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 7991a90..3b964a4 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -2,15 +2,17 @@
 
 shopt -s nullglob globstar
 
-typeit=0
-typeandcopy=0
-if [[ $1 == "--type" ]]; then
-	typeit=1
-	shift
-elif [[ $1 == "--type-and-copy" ]] ; then
-	typeandcopy=1
-	shift
-fi
+action=copy
+case $1 in
+	--type)
+		action=type
+		shift
+		;;
+	--type-and-copy)
+		action=typeandcopy
+		shift
+		;;
+esac
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
@@ -26,21 +28,24 @@ copy_password () {
 }
 
 type_password () {
-	pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } |
+	pass show "$password" | head -n 1 | tr -d '\n' |
 		xdotool type --clearmodifiers --file -
 }
 
 type_username () {
-	pass show "$password" | head -n 2 | tail -n +2 |
-		{ IFS= read -r pass; printf %s "$pass"; } |
+	pass show "$password" | head -n 2 | tail -n +2 | tr -d '\n' |
 		xdotool type --clearmodifiers --file -
 }
 
-if [[ $typeit -eq 1 ]] ; then
-	type_password
-elif [[ $typeandcopy -eq 1 ]]; then
-	type_username
-	copy_password
-else
-	copy_password
-fi
+case $action in
+	copy)
+		copy_password
+		;;
+	type)
+		type_password
+		;;
+	typeandcopy)
+		type_username
+		copy_password
+		;;
+esac
-- 
2.22.0

From 7bdb73fd66bb7d38278e9cedf0c726a27ec49c3d Mon Sep 17 00:00:00 2001
From: John Gliksberg <[email protected]>
Date: Tue, 9 Jul 2019 10:47:01 +0200
Subject: [PATCH 1/2] dmenu: Add ``type and copy'' scheme

---
 contrib/dmenu/passmenu | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 83268bc..7991a90 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -3,9 +3,13 @@
 shopt -s nullglob globstar
 
 typeit=0
+typeandcopy=0
 if [[ $1 == "--type" ]]; then
 	typeit=1
 	shift
+elif [[ $1 == "--type-and-copy" ]] ; then
+	typeandcopy=1
+	shift
 fi
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
@@ -17,9 +21,26 @@ password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
 
 [[ -n $password ]] || exit
 
-if [[ $typeit -eq 0 ]]; then
+copy_password () {
 	pass show -c "$password" 2>/dev/null
-else
+}
+
+type_password () {
 	pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } |
 		xdotool type --clearmodifiers --file -
+}
+
+type_username () {
+	pass show "$password" | head -n 2 | tail -n +2 |
+		{ IFS= read -r pass; printf %s "$pass"; } |
+		xdotool type --clearmodifiers --file -
+}
+
+if [[ $typeit -eq 1 ]] ; then
+	type_password
+elif [[ $typeandcopy -eq 1 ]]; then
+	type_username
+	copy_password
+else
+	copy_password
 fi
-- 
2.22.0

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

Reply via email to