otp in passmenu

Gildásio Júnior gildasiojunior at riseup.net
Fri Apr 9 02:09:03 UTC 2021


Hi all,

I have the same demand as Alessandro Accardo mentioned in Sep 2018 [0].
He submited a patch, receive a feedback, updated it and I couldn't see
any other new feedback.

I had patched passmenu to support pass-otp too (in a bigger way than 
he did). I'm sending my patch to receive some feedback and talk about 
the demand we have.

Anyway, thanks for your work. pass and passmenu as well are projects
that I like a lot. Thank you.

PS: I didn't have experience contribut with git patches by email. So
please let me know if I did something wrong and how can get the right
path.

[0]: https://lists.zx2c4.com/pipermail/password-store/2018-September/003406.html

-- 
[]'s
Gildásio Júnior
-------------- next part --------------
From bbfce317691dd9db9ac8b6bbd729a70260032dbf Mon Sep 17 00:00:00 2001
From: Gildasio Junior <gildasiojunior at riseup.net>
Date: Thu, 8 Apr 2021 23:04:44 -0300
Subject: [PATCH] Add pass-otp support in passmenu

---
 contrib/dmenu/README.md |  6 ++++--
 contrib/dmenu/passmenu  | 41 +++++++++++++++++++++++++++++++++--------
 2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/contrib/dmenu/README.md b/contrib/dmenu/README.md
index 9d54fb4..5e1b4ec 100644
--- a/contrib/dmenu/README.md
+++ b/contrib/dmenu/README.md
@@ -2,12 +2,14 @@
 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 copied to the clipboard. If `--otp` is specified, the password is
+interpreted as a 2fa OTP token using [pass-otp][].
 
 # Usage
 
-    passmenu [--type] [dmenu arguments...]
+    passmenu [--type] [--otp] [dmenu arguments...]
 
 [dmenu]: http://tools.suckless.org/dmenu/
 [xdotool]: http://www.semicomplete.com/projects/xdotool/
 [pass]: http://www.zx2c4.com/projects/password-store/
+[pass-otp]: https://github.com/tadfisher/pass-otp
diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 83268bc..e278330 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -2,24 +2,49 @@
 
 shopt -s nullglob globstar
 
+prefix=${PASSWORD_STORE_DIR-~/.password-store}
 typeit=0
-if [[ $1 == "--type" ]]; then
-	typeit=1
-	shift
-fi
+otp=''
+dir2fa=''
+dmenu_options=''
+
+while [[ $# -gt 0 ]]
+do
+option="$1"
+
+case $option in
+	--type)
+		typeit=1
+		shift
+		;;
+	--otp)
+		otp='otp'
+		dir2fa='2fa/'
+		prefix=${PASSWORD_STORE_DIR-~/.password-store/$dir2fa}
+		shift
+		;;
+	*)
+		dmenu_options="${dmenu_options} ${option}"
+		shift
+		;;
+esac
+done
 
-prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
 password_files=( "${password_files[@]#"$prefix"/}" )
 password_files=( "${password_files[@]%.gpg}" )
 
-password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
+if [[ $otp == '' ]]; then
+	password=$(printf '%s\n' "${password_files[@]}" | grep -v '2fa/' | dmenu $dmenu_options "$@")
+else
+	password=$(printf '%s\n' "${password_files[@]}" | dmenu $dmenu_options "$@")
+fi
 
 [[ -n $password ]] || exit
 
 if [[ $typeit -eq 0 ]]; then
-	pass show -c "$password" 2>/dev/null
+	pass $otp show -c "$dir2fa$password" 2>/dev/null
 else
-	pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } |
+	pass $otp show "$dir2fa$password" | { IFS= read -r pass; printf %s "$pass"; } |
 		xdotool type --clearmodifiers --file -
 fi
-- 
2.31.1

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20210408/ab44ddb1/attachment.sig>


More information about the Password-Store mailing list