[pass] [PATCH] Add ability to select line in passmenu

Jonas Kalderstam jonas at cowboyprogrammer.org
Sun Feb 7 15:59:32 CET 2016


This adds the following additional argument to passmenu:

    passmenu --line=2

It does make use of sed to be able to type the specified line, which
might or might not be an issue.
---
 contrib/dmenu/README.md | 13 +++++++------
 contrib/dmenu/passmenu  | 25 ++++++++++++++++++-------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/contrib/dmenu/README.md b/contrib/dmenu/README.md
index 9d54fb4..ab6afaa 100644
--- a/contrib/dmenu/README.md
+++ b/contrib/dmenu/README.md
@@ -1,12 +1,13 @@
-`passmenu` is a [dmenu][]-based interface to [pass][], the standard Unix
-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.
+`passmenu` is a [dmenu][]-based interface to [pass][], the standard
+Unix 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. Use `--line=N` to specify which line to copy/type.
 
 # Usage
 
-    passmenu [--type] [dmenu arguments...]
+    passmenu [--type] [--line=N] [dmenu arguments...]
 
 [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..fdae88f 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -3,10 +3,20 @@
 shopt -s nullglob globstar
 
 typeit=0
-if [[ $1 == "--type" ]]; then
-       typeit=1
-       shift
-fi
+line=1
+
+for arg in "$@"; do
+  case $arg in
+    --type)
+      typeit=1
+      shift
+      ;;
+    --line=*)
+      line="${arg#*=}"
+      shift
+      ;;
+  esac
+done
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
@@ -18,8 +28,9 @@ password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
 [[ -n $password ]] || exit
 
 if [[ $typeit -eq 0 ]]; then
-       pass show -c "$password" 2>/dev/null
+  pass show -c"$line" "$password" 2>/dev/null
 else
-       pass show "$password" | { read -r pass; printf %s "$pass"; } |
-               xdotool type --clearmodifiers --file -
+  pass show "$password" | sed -n "$line"p |
+    { read -r pass; printf %s "$pass"; } |
+       xdotool type --clearmodifiers --file -
 fi
-- 
2.7.0

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20160207/cf63a6d4/attachment.asc>


More information about the Password-Store mailing list