[PATCH] clip: add option PASSWORD_STORE_PASTE_ONCE

Matthias Groß grmat at sub.red
Tue Mar 29 17:05:08 UTC 2022


If this environment variable is set to "true", the clipboard is cleared
immediately after pasting.

---
I've send this in before but the first try was a bit chaotic and I never
got feedback. I still consider it a useful feature and rebased it onto
master. However, if silence meant "no", sorry for the noise.

 man/pass.1            | 4 ++++
 src/password-store.sh | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/man/pass.1 b/man/pass.1
index a555dcb..5930cdd 100644
--- a/man/pass.1
+++ b/man/pass.1
@@ -429,6 +429,10 @@ for more info.
 Specifies the number of seconds to wait before restoring the clipboard, by default
 \fI45\fP seconds.
 .TP
+.I PASSWORD_STORE_PASTE_ONCE
+If this variable is set to \fItrue\fP, the clipboard is cleared immediately after the copied
+password has been pasted.
+.TP
 .I PASSWORD_STORE_UMASK
 Sets the umask of all files modified by pass, by default \fI077\fP.
 .TP
diff --git a/src/password-store.sh b/src/password-store.sh
index 22e818f..ab13a78 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -16,6 +16,7 @@ PREFIX="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
 EXTENSIONS="${PASSWORD_STORE_EXTENSIONS_DIR:-$PREFIX/.extensions}"
 X_SELECTION="${PASSWORD_STORE_X_SELECTION:-clipboard}"
 CLIP_TIME="${PASSWORD_STORE_CLIP_TIME:-45}"
+PASTE_ONCE="${PASSWORD_STORE_PASTE_ONCE:-false}"
 GENERATED_LENGTH="${PASSWORD_STORE_GENERATED_LENGTH:-25}"
 CHARACTER_SET="${PASSWORD_STORE_CHARACTER_SET:-[:punct:][:alnum:]}"
 CHARACTER_SET_NO_SYMBOLS="${PASSWORD_STORE_CHARACTER_SET_NO_SYMBOLS:-[:alnum:]}"
@@ -162,11 +163,17 @@ clip() {
 			copy_cmd+=( --primary )
 			paste_cmd+=( --primary )
 		fi
+		if [[ $PASTE_ONCE == true ]]; then
+			copy_cmd+=( --paste-once )
+		fi
 		local display_name="$WAYLAND_DISPLAY"
 	elif [[ -n $DISPLAY ]] && command -v xclip &> /dev/null; then
 		local copy_cmd=( xclip -selection "$X_SELECTION" )
 		local paste_cmd=( xclip -o -selection "$X_SELECTION" )
 		local display_name="$DISPLAY"
+		if [[ $PASTE_ONCE == true ]]; then
+			copy_cmd+=( -loops 1 )
+		fi
 	else
 		die "Error: No X11 or Wayland display and clipper detected"
 	fi
-- 
2.35.1



More information about the Password-Store mailing list