Okay, I just discovered shellcheck so here is an error free patch

On Sun, May 26, 2019 at 7:18 AM Balázs Váradi <[email protected]> wrote:

> Hi all,
>
> After using pass and passmenu for some time, my problem is that if the gpg
> pinentry window pops up sometimes other programs can steal focus upon the
> closing of that window. This pull request adds the following:
>
>    1. An option to reactivate the currently active window with the -a or
>    --activate option
>    2. A -t shortcut for the --type option and also the handling of -at or
>    -ta
>    3. A check for the existence of xdotool
>    4. Return codes for failure:
>       1. Cancelled selection (1)
>       2. xdotool not found in path and it is required by a option (2)
>
> As I'm using gmail I couldn't find a way to insert the patch without
> loosing the spaces, so I attached it. Hope it is okay and this can help to
> someone else too.
>
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEEa3x2MSMZ6TOzrbsbfPTaG2Lx3gFAlzqI5cACgkQbfPTaG2L
x3jDFRAAwjLLrg4k5Waq4K+Xla2SGP0x01Z1oqG1hMvDOa7HOtAWbnNwl1njPDkN
oz/Jo+TghIIVvREHdzBhDh48DMY6Mfq94yra7IILZMYnzko56++MiIZqCFWhnDDC
A0sDoiSjm+bokMqW+A5l4cICpU4hmE4b5D6leXX5zC0R6f1jBr59K0BP03NtFM0W
F+3GtIwdg+VGA5Zd3TtM7DA68655cis1tzD1GoGw/RcdLeYrcY+bzlngR09VWx8U
6yo9CMxjMXPXuNz5W7B6Ppz7xes6beoX0xk7fDboSVIHr5Bwu7mok49ZUKGUXudJ
WDdhugRChp0YEoYeDIGllXOMx8SJs4yhjtyVgqHzBx1HUcd/ctq9/CSGG1OmCb4H
GfrexU2qoOYy5dm6cyf9N8vSx+yiCSmmTXc6ap3sGyJr1ZMDh0v7v8pFk7Ua9rYw
cUVjvjP1wVRyKUqiB80aISbVqXqMkAE08Ep4y6hlikldJl56clXuOFtazNogkhUg
Fvt2wXRq6MsOrYWWDCz3gtuR8k17eT5ZXXCm8S2zUwFzwUjTsspLVOUbC+dbyo7+
JB5t+ioOJOBP8RPXGVEvbq5Sp/+D8c2T70uMftNvpyuZKtVEf9lZOG1vWc3UnJGt
xjjwXGlh/U8v7rE7W9wUTleBgqk806tJ81SgHkmlUxM6dAhcKlo=
=974T
-----END PGP SIGNATURE-----
From 38cbf06c025202dae76913feb5dde72baa998d36 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20V=C3=A1radi?= <[email protected]>
Date: Sun, 26 May 2019 07:10:50 +0200
Subject: [PATCH] Add activate option to passmenu

---
 contrib/dmenu/README.md |  6 +++--
 contrib/dmenu/passmenu  | 54 +++++++++++++++++++++++++++++++++++------
 2 files changed, 51 insertions(+), 9 deletions(-)

diff --git a/contrib/dmenu/README.md b/contrib/dmenu/README.md
index 9d54fb4..52baca3 100644
--- a/contrib/dmenu/README.md
+++ b/contrib/dmenu/README.md
@@ -1,12 +1,14 @@
 `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][]
+one open. If `-a` or `--activate` is specified the currently active window will
+be made active again after copying/before typing the password using [xdotool][].
+If `-t` or `--type` is specified, the password is typed using [xdotool][]
 instead of copied to the clipboard.
 
 # Usage
 
-    passmenu [--type] [dmenu arguments...]
+    passmenu [-a|--activate] [-t|--type] [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 83268bc..fcd02c8 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -2,11 +2,46 @@
 
 shopt -s nullglob globstar
 
+type -P xdotool > /dev/null
+xdotool_available=$?
+
 typeit=0
-if [[ $1 == "--type" ]]; then
+set_typeit(){
+	if [[ $xdotool_available -ne 0 ]]; then
+		echo For typed password support please install xdotool.
+		exit 2
+	fi
 	typeit=1
-	shift
-fi
+}
+
+set_active_window(){
+	if [[ $xdotool_available -ne 0 ]]; then
+		echo For window activation support please install xdotool.
+		exit 2
+	fi
+	active_window=$(xdotool getactivewindow)
+}
+
+while [[ $# -gt 0 ]]; do
+	case $1 in
+	-t|--type)
+		set_typeit
+		shift
+	;;
+	-a|--activate)
+		set_active_window
+		shift
+	;;
+	-at|-ta)
+		set_active_window
+		set_typeit
+		shift
+	;;
+	*)
+		break
+	esac
+done
+
 
 prefix=${PASSWORD_STORE_DIR-~/.password-store}
 password_files=( "$prefix"/**/*.gpg )
@@ -15,11 +50,16 @@ password_files=( "${password_files[@]%.gpg}" )
 
 password=$(printf '%s\n' "${password_files[@]}" | dmenu "$@")
 
-[[ -n $password ]] || exit
+[[ -n $password ]] || exit 1
 
 if [[ $typeit -eq 0 ]]; then
 	pass show -c "$password" 2>/dev/null
+
+	if [[ -n "${active_window}" ]]; then
+		xdotool windowactivate "$active_window"
+	fi
 else
-	pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } |
-		xdotool type --clearmodifiers --file -
-fi
+	pass show "$password" | { IFS= read -r pass;
+		[[ -n "${active_window}" ]] && xdotool windowactivate "$active_window";
+		printf %s "$pass"; } | xdotool type --clearmodifiers --file -
+fi
\ No newline at end of file
-- 
2.17.1

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

Reply via email to