[PATCH] clip: Allow more than one $X_SELECTION

Oskar Wiksten passstore_pr at iostr.com
Mon Jul 3 22:46:09 CEST 2017


Allows `--clip` to copy the password to more than one `xclip` selection. This
is done by allowing multiple values in `$X_SELECTION`, separated by space,
instead of only one xclip selection. Change is backwards-compatible with
existing configurations for `X_SELECTION`.

Example:
```
PASSWORD_STORE_X_SELECTION="primary clipboard" pass --clip identifier
```
will copy the password to both `primary` and `clipboard` selections via
`xclip`.

Reason for wanting to have the password in more than one X selection is that
different programs use different X selections when pasting (my `xterm` uses
`primary` on ctrl-shift-insert but firefox uses `clipboard` for the same
keyboard combination). If applied, this change will make it possible to
configure `pass` in a way that such differences are not as noticeable.

The behaviour of copying to both `primary` and `clipboard` is also seen in
other password managers (such as keepassx).
---
 src/password-store.sh | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index d77ff12..3f69911 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -156,11 +156,12 @@ clip() {
 	# trailing new lines.
 	local sleep_argv0="password store sleep on display $DISPLAY"
 	pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
-	local before="$(xclip -o -selection "$X_SELECTION" 2>/dev/null | base64)"
-	echo -n "$1" | xclip -selection "$X_SELECTION" || die "Error: Could not copy data to the clipboard"
+	for sel in $X_SELECTION ; do
+	local before="$(xclip -o -selection "$sel" 2>/dev/null | base64)"
+	echo -n "$1" | xclip -selection "$sel" || die "Error: Could not copy data to the clipboard"
 	(
 		( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '$CLIP_TIME' & wait" )
-		local now="$(xclip -o -selection "$X_SELECTION" | base64)"
+		local now="$(xclip -o -selection "$sel" | base64)"
 		[[ $now != $(echo -n "$1" | base64) ]] && before="$now"
 
 		# It might be nice to programatically check to see if klipper exists,
@@ -172,8 +173,9 @@ clip() {
 		# so we axe it here:
 		qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory &>/dev/null
 
-		echo "$before" | base64 -d | xclip -selection "$X_SELECTION"
+		echo "$before" | base64 -d | xclip -selection "$sel"
 	) 2>/dev/null & disown
+	done
 	echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
 }
 
-- 
2.13.2



More information about the Password-Store mailing list