[pass] [PATCH 1/3] Add hook for a callback after copying to clipboard

Emil Lundberg lundberg.emil at gmail.com
Sat Jul 25 18:21:35 CEST 2015


The primary intended purpose of this functionality is to allow wrapper
utilities such as passmenu to do something after pass has copied the
password to the clipboard. This is not previously possible since xclip
prevents the pass script from exiting.

How to use: export a function named PASSWORD_STORE_POST_COPY_HOOK. If
present, this function will be called with two arguments:

 1. The name of the copied password (`"foo/bar"` when pass is invoked as
    `"pass foo/bar"`)
 2. A copy of the message pass prints to the console

Example:

    PASSWORD_STORE_POST_COPY_HOOK() {
      notify-send -u normal -t 2000 "Copied $1" "$2"
    }
    export -f PASSWORD_STORE_POST_COPY_HOOK
    pass foo/bar
---
 src/password-store.sh | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index d535a74..0c21f21 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -119,6 +119,10 @@ check_sneaky_paths() {
 	done
 }
 
+function_exists() {
+	type $1 >/dev/null && [[ "$(type -t $1)" -eq "function" ]]
+}
+
 #
 # END helper functions
 #
@@ -151,7 +155,13 @@ clip() {
 
 		echo "$before" | base64 -d | xclip -selection "$X_SELECTION"
 	) 2>/dev/null & disown
-	echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
+
+	local copied_message="Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
+	echo "$copied_message"
+
+	if function_exists 'PASSWORD_STORE_POST_COPY_HOOK'; then
+		PASSWORD_STORE_POST_COPY_HOOK "$2" "$copied_message"
+	fi
 }
 tmpdir() {
 	[[ -n $SECURE_TMPDIR ]] && return
-- 
2.4.6



More information about the Password-Store mailing list