m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2012-08-06 23:33:58 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2012-08-06 23:33:58 +0200
commit65cc7726f316139c3af98627decbd5b015ed2df4 (patch)
tree04743eb6c3992b56fb228a5554ffca126928f6cc
parentb5405f533c66cceb9820b9055d4bd1381a4b2767 (diff)
Deal with klipper and new lines.
-rwxr-xr-xpassword-store.sh22
1 files changed, 19 insertions, 3 deletions
diff --git a/password-store.sh b/password-store.sh
index 7b8c838..8882d5f 100755
--- a/password-store.sh
+++ b/password-store.sh
@@ -45,9 +45,25 @@ isCommand() {
esac
}
clip() {
- before="$(xclip -o -selection clipboard)"
- echo "$1" | xclip -selection clipboard
- (sleep 45s; echo "$before" | xclip -selection clipboard) & disown
+ # This base64 business is a disgusting hack to deal with newline inconsistancies
+ # 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.
+
+ before="$(xclip -o -selection clipboard | base64)"
+ echo -n "$1" | xclip -selection clipboard
+ (
+ sleep 5s
+ now="$(xclip -o -selection clipboard | base64)"
+ if [[ $now != $(echo -n "$1" | base64) ]]; then
+ before="$now"
+ fi
+ # It might be nice to programatically check to see if klipper exists,
+ # as well as checking for other common clipboard managers. But for now,
+ # this works fine. Clipboard managers frequently write their history
+ # out in plaintext, so we axe it here.
+ qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory >/dev/null 2>&1
+ echo "$before" | base64 -d | xclip -selection clipboard
+ ) & disown
echo "Copied $2 to clipboard. Will clear in 45 seconds."
}