commit 2c9c36e3ca8eab1a3f9056d18619f80cedf3781d
parent 553d096111061b749bd17e5fe386c5ff6c888e1e
Author: Jason A. Donenfeld <Jason@zx2c4.com>
Date: Thu, 20 Mar 2014 00:45:52 -0600
clip: don't race between pass instances in restore
We now make sure a previous pass clip restore finishes immediately when
copying another password to the clipboard.
This is currently only implemented on Linux.
Diffstat:
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/password-store.sh b/src/password-store.sh
@@ -113,10 +113,12 @@ clip() {
# in shell. There must be a better way to deal with this, but because I'm a dolt,
# we're going with this for now.
+ sleep_argv0="password store sleep on display $DISPLAY"
+ kill -9 $(grep -l -r --include="cmdline" "^$sleep_argv0" /proc/ 2>/dev/null | sed -n 's:/proc/\([0-9]\+\)/.*:\1:p' | sort | uniq) 2>/dev/null && sleep 0.1
before="$(xclip -o -selection clipboard | base64)"
echo -n "$1" | xclip -selection clipboard
(
- sleep 45
+ ( exec -a "$sleep_argv0" sleep 45 )
now="$(xclip -o -selection clipboard | base64)"
[[ $now != $(echo -n "$1" | base64) ]] && before="$now"
@@ -130,7 +132,7 @@ clip() {
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory &>/dev/null
echo "$before" | base64 -d | xclip -selection clipboard
- ) & disown
+ ) 2>/dev/null & disown
echo "Copied $2 to clipboard. Will clear in 45 seconds."
}
tmpdir() {