[pass] why copy to clipboard?

Brian Mattern rephorm at rephorm.com
Wed Dec 5 21:13:57 CET 2012


On Wed, 05 Dec 2012, milki wrote:
> Hm. Looking at some other password managers, I see them using xsel
> instead of xclip. The default xsel also uses the primary clipboard
> selection.

Both xclip and xsel use the primary selection by default. pass
explicitly chooses to use the clipboard:

$ grep xclip password-store.sh
  before="$(xclip -o -selection clipboard | base64)"
    echo -n "$1" | xclip -selection clipboard
        now="$(xclip -o -selection clipboard | base64)"
            echo "$before" | base64 -d | xclip -selection clipboard

This can easily be made configurable, e.g., with the attached patch.
(just export PASSWORD_STORE_XCLIP_SELECTION=primary)

Alternatively, we could add separate flags for "copy to primary" and
"copy to clipboard".

Brian
-------------- next part --------------
From c01f0d7dafae3dc7881c45c6f4bb7229938c4e2c Mon Sep 17 00:00:00 2001
From: Brian Mattern <rephorm at rephorm.com>
Date: Wed, 5 Dec 2012 12:11:25 -0800
Subject: [PATCH] allow setting the X selection to copy to

---
 src/password-store.sh | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 8afc67e..b344cbf 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -9,6 +9,7 @@ PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
 ID="$PREFIX/.gpg-id"
 GIT_DIR="${PASSWORD_STORE_GIT:-$PREFIX}/.git"
 GPG_OPTS="--quiet --yes --batch"
+XCLIP_SELECTION="${PASSWORD_STORE_XCLIP_SELECTION:-clipboard}"
 
 export GIT_DIR
 export GIT_WORK_TREE="${PASSWORD_STORE_GIT:-$PREFIX}"
@@ -85,11 +86,11 @@ 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.
 
-	before="$(xclip -o -selection clipboard | base64)"
-	echo -n "$1" | xclip -selection clipboard
+	before="$(xclip -o -selection ${XCLIP_SELECTION} | base64)"
+	echo -n "$1" | xclip -selection ${XCLIP_SELECTION}
 	(
 		sleep 45
-		now="$(xclip -o -selection clipboard | base64)"
+		now="$(xclip -o -selection ${XCLIP_SELECTION} | base64)"
 		if [[ $now != $(echo -n "$1" | base64) ]]; then
 			before="$now"
 		fi
@@ -103,7 +104,7 @@ clip() {
 		# so we axe it here:
 		qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory &>/dev/null
 
-		echo "$before" | base64 -d | xclip -selection clipboard
+		echo "$before" | base64 -d | xclip -selection ${XCLIP_SELECTION}
 	) & disown
 	echo "Copied $2 to clipboard. Will clear in 45 seconds."
 }
-- 
1.8.0



More information about the Password-Store mailing list