]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Adding xclip action thanks to password-store
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 20 Feb 2014 02:38:36 +0000 (23:38 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 20 Feb 2014 02:38:36 +0000 (23:38 -0300)
ChangeLog
lib/keyringer/actions/clip [new symlink]
lib/keyringer/actions/xclip [new file with mode: 0755]

index 17f343e643e85cb483069d1e9143458f8b7ca051..f94fb74014a7da60c30cefd3597bf5ec72175b6e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,6 @@
-2014-02-12 - Silvio Rhatto  <rhatto@riseup.net>
+2014-02-19 - Silvio Rhatto  <rhatto@riseup.net>
+
+       Added xclip action (#33)
 
        Check key expirations (#37)
 
diff --git a/lib/keyringer/actions/clip b/lib/keyringer/actions/clip
new file mode 120000 (symlink)
index 0000000..8b8c16c
--- /dev/null
@@ -0,0 +1 @@
+xclip
\ No newline at end of file
diff --git a/lib/keyringer/actions/xclip b/lib/keyringer/actions/xclip
new file mode 100755 (executable)
index 0000000..414013b
--- /dev/null
@@ -0,0 +1,53 @@
+#!/bin/bash
+#
+# Decrypt secret header to clipboard.
+#
+
+# Copy contents to clipboard.
+# Function thanks to Password Store by Jason A. Donenfeld <Jason@zx2c4.com>
+# distributed under GPLv2+: http://www.zx2c4.com/projects/password-store/
+clip() {
+       # 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 45
+               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 -- if qdbus isn't there or if klipper isn't running,
+               # this essentially becomes a no-op.
+               #
+               # 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
+
+               echo "$before" | base64 -d | xclip -selection clipboard
+       ) & disown
+       echo "Copied $2 to clipboard. Will clear in 45 seconds."
+}
+
+# Load functions
+LIB="`dirname $0`/../functions"
+source "$LIB" || exit 1
+
+# Get file
+keyringer_get_file "$2"
+
+# Decrypt
+pass="$($GPG --use-agent -d "$KEYDIR/$FILE" | head -n 1)"
+
+# Copy to clipboard
+if [ ! -z "$pass" ]; then
+  clip "$pass" "$2"
+fi
+
+# Exit
+exit "$?"