From 2c9c36e3ca8eab1a3f9056d18619f80cedf3781d Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 20 Mar 2014 00:45:52 -0600 Subject: 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. --- src/password-store.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/password-store.sh b/src/password-store.sh index 6fa32c1..f7ad52b 100755 --- 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() { -- cgit v1.2.3