[PATCH v3 1/2] clip: copy password into all displays if possible

Daniel Cordero pass at 0xdc.io
Fri May 29 18:44:36 CEST 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 both 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 any that are available.
Move the shared code into a separate function that can be called by each
code path.

Only error if we couldn't attempt a copy into either clipboard.
---
 src/password-store.sh | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 77f3eda..9533bf5 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -153,7 +153,8 @@ check_sneaky_paths() {
 #
 
 clip() {
-	if [[ -n $WAYLAND_DISPLAY ]]; then
+	wlchecks=$([[ -n $WAYLAND_DISPLAY ]] && command -v wl-copy 2>/dev/null)
+	if [[ -n "$wlchecks" ]]; then
 		local copy_cmd=( wl-copy )
 		local paste_cmd=( wl-paste -n )
 		if [[ $X_SELECTION == primary ]]; then
@@ -161,13 +162,23 @@ clip() {
 			paste_cmd+=( --primary )
 		fi
 		local display_name="$WAYLAND_DISPLAY"
-	elif [[ -n $DISPLAY ]]; then
+		doclip "$@" Wayland
+	fi
+
+	x11checks=$([[ -n $DISPLAY ]] && command -v xclip 2>/dev/null)
+	if test "$x11checks"; then
 		local copy_cmd=( xclip -selection "$X_SELECTION" )
 		local paste_cmd=( xclip -o -selection "$X_SELECTION" )
 		local display_name="$DISPLAY"
-	else
+		doclip "$@" X11
+	fi
+
+	if [[ -z "$wlchecks" ]] && [[ -z "$x11checks" ]]; then
 		die "Error: No X11 or Wayland display detected"
 	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 +203,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.26.2



More information about the Password-Store mailing list