[pass] [PASS][PATCH] Delayed file-lock improves corner-case. (new feature passmenu multi-clip)
mitfree
lists at ampling.com
Sat May 14 23:14:39 CEST 2016
In this patch, I've moved the filelock and all clipboard calls to after dmenu.
This allows you to escape dmenu without effecting the clipboard. Say
"xyz" is in your clipboard. You run passmenu and select a url, login and
password. Then you start passmenu again, but change your mind and hit escape.
The behavior previously would restore your clipboard to "xyz". The new
behavior keeps the selected passwords in queue. I find this behavior
preferable.
Calling dmenu sooner should also have a small added benefit of making
the start of the program feel somewhat faster on slow machines.
I'm attaching two files.
passmenu_multi-clip.patch # Contains 11 commits.
0001-Delayed-file-lock-improves-corner-case.patch # Contains 1 commit.
e6f32f4d33fe022c4b13def31c401890298e5b1e
contrib/dmenu/passmenu | 51 +++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/contrib/dmenu/passmenu b/contrib/dmenu/passmenu
index 68b4150..40dfe97 100755
--- a/contrib/dmenu/passmenu
+++ b/contrib/dmenu/passmenu
@@ -17,25 +17,37 @@ prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
password_files=( "$prefix"/**/*.gpg )
password_files=( "${password_files[@]#"$prefix"/}" )
password_files=( "${password_files[@]%.gpg}" )
-password=( ${password:-""} )
-before=( "${before:-}" )
-userID="$(id -u $(whoami))"
-stalelock=( "${stalelock:-""}" )
-stalelock=( "$(find '/tmp' -maxdepth 1 -name "passmenulock."$userID".*" -user $(whoami) -print0 -quit)" ) &&
-cleanup=True || { true; cleanup=False; }
+password=( '' )
+cleanup=( '' )
+before=( '' )
+userID=( "$(id -u $(whoami))" )
_finish () {
- [[ -n $before ]] &&
+ [[ True == $cleanup ]] &&
printf "$before" | base64 -d | xclip -sel "$X_SELECTION" -i
[[ True = "$cleanup" ]] &&
if compgen -G "/tmp/passmenulock.1000*" >/dev/null 2>&1 ;then
- rmdir /tmp/passmenulock."$userID".* >/dev/null 2>&1
+ rmdir /tmp/passmenulock.*.*."$$" >/dev/null 2>&1
fi
exit
}
+
+## dmenu exits on KeyPress not KeyRelease.
+# It might be nice to send KeyRelease event to some dummy window.
+# psydocode: xdotool getwindowfocus; create dummy window;
+# exec dmenu; close dummy window; restore focus.
+for password in $(printf '%s\n' "${password_files[@]}" | dmenu -f "$@"); do
+ passel+=("$password")
+done
+
+[[ -n $password ]] || exit
+
trap _finish EXIT
-## Clearing stale Xclip loops avoids a posible race condition.
+## Clearing old filelock(s).
+umask 077
+stalelock=( "${stalelock:-''}" )
+stalelock=( "$(find '/tmp' -maxdepth 1 -name "passmenulock."$userID".*" -user $(whoami) -print0 -quit)" ) &&
if test -n "$stalelock" ;then
report=( "$(ps -u $(id -u $(whoami)) aux | grep "bash" |
grep "passmenu" | grep -v "$$")" )
@@ -44,26 +56,19 @@ if test -n "$stalelock" ;then
if [[ "$report" == *"$stalePID"* ]] ;then
kill "$stalePID" || exit 1
else
- rmdir /tmp/passmenulock.$userID.* >/dev/null 2>&1 || exit 1
+ rmdir /tmp/passmenulock."$userID".* >/dev/null 2>&1 ||
+ { echo ":: Unable to clear old filelock"; exit 1; }
fi
fi
-## dmenu exits on KeyPress not KeyRelease.
-# It would be nice to send KeyRelease event to some dummy window.
-# psydocode: xdotool getwindowfocus; create dummy window;
-# exec dmenu; close dummy window; restore focus.
-for password in $(printf '%s\n' "${password_files[@]}" | dmenu -f "$@"); do
- passel+=("$password")
-done
-
-[[ -n $password ]] || exit
-# It would be nice to first somehow test if string exists.
-before="$(xclip -sel "$X_SELECTION" -o 2>/dev/null | base64)" || true
-
-umask 077
+## Adding a new filelock
( mktemp -d "/tmp/passmenulock."$userID".XXXXXXXXXX"."$$" >/dev/null 2>&1 && cleanup=True ||
{ echo >&2 ":: Unable to make a filelock."; exit 1; } )
+cleanup=True
+# It would be nice to first first test if string exists.
+before="$(xclip -sel "$X_SELECTION" -o 2>/dev/null | base64)" || true
+
if [[ $typeit -eq 0 ]]; then
if [ ${#passel[@]} -gt "1" ]; then
round=0
--
At your service,
mitfree
http://ampling.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: passmenu_multi-clip.patch
Type: text/x-diff
Size: 26266 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20160514/40540e71/attachment-0002.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Delayed-file-lock-improves-corner-case.patch
Type: text/x-diff
Size: 3436 bytes
Desc: not available
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20160514/40540e71/attachment-0003.patch>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: signature
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20160514/40540e71/attachment-0001.asc>
More information about the Password-Store
mailing list