[pass] [PATCH 1/2] clip: split into functions

Marc-Antoine Perennou Marc-Antoine at Perennou.com
Thu Sep 11 11:12:45 CEST 2014


Signed-off-by: Marc-Antoine Perennou <Marc-Antoine at Perennou.com>
---
 src/password-store.sh | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 2287a46..dbeb710 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -135,19 +135,21 @@ check_sneaky_paths() {
 # BEGIN platform definable
 #
 
-clip() {
+clip_sleep() {
+	( exec -a "$1" sleep "$CLIP_TIME" )
+}
+
+clip_xclip() {
 	# This base64 business is because bash cannot store binary data in a shell
 	# variable. Specifically, it cannot store nulls nor (non-trivally) store
 	# 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" | base64)"
-	echo -n "$1" | xclip -selection "$X_SELECTION"
+	echo -n "$2" | xclip -selection "$X_SELECTION"
 	(
-		( exec -a "$sleep_argv0" sleep "$CLIP_TIME" )
+		clip_sleep "$1"
 		local now="$(xclip -o -selection "$X_SELECTION" | base64)"
-		[[ $now != $(echo -n "$1" | base64) ]] && before="$now"
+		[[ $now != $(echo -n "$2" | base64) ]] && before="$now"
 
 		# It might be nice to programatically check to see if klipper exists,
 		# as well as checking for other common clipboard managers. But for now,
@@ -160,6 +162,12 @@ clip() {
 
 		echo "$before" | base64 -d | xclip -selection "$X_SELECTION"
 	) 2>/dev/null & disown
+}
+
+clip() {
+	local sleep_argv0="password store sleep on display $DISPLAY"
+	pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
+	clip_xclip "$sleep_argv0" "$@"
 	echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
 }
 tmpdir() {
-- 
2.1.0



More information about the Password-Store mailing list