From b233e63d82d5e93aaeb6e34c5a3baba8ab12bd67 Mon Sep 17 00:00:00 2001
From: John Gliksberg <jg.trosh@gmail.com>
Date: Fri, 14 Apr 2017 21:29:37 +0200
Subject: [PATCH 2/3] [passmenu] Add --type-and-copy argument

Type last part of the password identifier (usually user login)
and copy password to clipboard.

Practical for usual web-like login methods to reduce typing:

  * Place cursor in user login field
  * Invoke `passmenu --type-and-copy` (keyboard shortcut)
  * In dmenu, search for desired password
  * If needed, enter GPG credentials
  * Place cursor in password field (usually <tab> or <enter>)
  * Paste from clipboard
  * Possibly tick a remember me field (usually <tab><space>)
  * Send login info (usually <tab><space> or <enter>)

IMO this makes web-like login fast and user-friendly.
---
 contrib/dmenu/passmenu | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)

diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index aff0ccf..8af5fd0 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -2,11 +2,19 @@
 
 shopt -s nullglob globstar
 
-typeit=0
-if [[ $1 == "--type" ]]; then
-	typeit=1
-	shift
-fi
+case "$1" in
+    --type )
+        typeit=1
+        shift
+        ;;
+    --type-and-copy )
+        typeit=2
+        shift
+        ;;
+    * )
+        typeit=0
+        ;;
+esac
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
@@ -17,9 +25,19 @@ password=$(printf '%s\n' "${password_files[@]}" | dmenu)
 
 [[ -n $password ]] || exit
 
-if [[ $typeit -eq 0 ]]; then
-	pass show -c "$password" 2>/dev/null
-else
-	pass show "$password" | { read -r pass; printf %s "$pass"; } |
-		xdotool type --clearmodifiers --file -
-fi
+case $typeit in
+    0 )
+        pass show -c "$password"
+        ;;
+    1 )
+        pass show "$password" \
+            | { read -r pass; printf %s "$pass"; } \
+            | xdotool type --clearmodifiers --file -
+        ;;
+    2 )
+        printf %s "$password" \
+            | grep -o "[^/]*$" \
+            | xdotool type --clearmodifiers --file -
+        pass show -c "$password"
+        ;;
+esac
-- 
2.12.2

