[PATCH] clip: copy password into all displays if possible

Daniel Cordero pass at 0xdc.io
Thu Feb 13 21:22:06 CET 2020


pass only attempts to copy the password, first into wayland or otherwise
X, and it may still fail if the clipboard command isn't installed.

However, when using a variety of wayland and Xwayland programs that need
password inputs, pass cannot know which clipboard it needs to place the
password.

Check the existance of the clipboard commands, and copy the password
into both the wayland and X clipboards.
Move the shared code into a separate function that can be called by each
code path.
---

Hi there,

throwing this out here to see if this is worthy of upstreaming; happy to
make edits, especially with bashisms/posix-isms.

I'm running sway with Xwayland and all sorts of applications, the
clipboard isn't automatically shared between wayland & X.

One thing I was considering is adding a -w flag that the user could use
to specify clipping to wayland clipboard, and that -wc would do both.

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

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..afdbb91 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -153,7 +153,7 @@ check_sneaky_paths() {
 #
 
 clip() {
-	if [[ -n $WAYLAND_DISPLAY ]]; then
+	if command -v wl-copy >/dev/null 2>&1 && [[ -n $WAYLAND_DISPLAY ]]; then
 		local copy_cmd=( wl-copy )
 		local paste_cmd=( wl-paste -n )
 		if [[ $X_SELECTION == primary ]]; then
@@ -161,13 +161,17 @@ clip() {
 			paste_cmd+=( --primary )
 		fi
 		local display_name="$WAYLAND_DISPLAY"
-	elif [[ -n $DISPLAY ]]; then
+		doclip "$@" Wayland
+	fi
+	if command -v xclip >/dev/null 2>&1 && [[ -n $DISPLAY ]]; then
 		local copy_cmd=( xclip -selection "$X_SELECTION" )
 		local paste_cmd=( xclip -o -selection "$X_SELECTION" )
 		local display_name="$DISPLAY"
-	else
-		die "Error: No X11 or Wayland display detected"
+		doclip "$@" X11
 	fi
+}
+
+doclip() {
 	local sleep_argv0="password store sleep on display $display_name"
 
 	# This base64 business is because bash cannot store binary data in a shell
@@ -192,7 +196,7 @@ clip() {
 
 		echo "$before" | $BASE64 -d | "${copy_cmd[@]}"
 	) >/dev/null 2>&1 & disown
-	echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
+	echo "Copied $2 to $3 clipboard. Will clear in $CLIP_TIME seconds."
 }
 
 qrcode() {
-- 
2.24.1


More information about the Password-Store mailing list