m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBrett Cornwall <brett@i--b.com>2019-02-27 00:08:33 -0700
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-27 15:15:25 +0100
commitb0b784b1a57c0b06936e6f5d6560712b4b810cd3 (patch)
treead112b2cca1a7dccc8464dfdc44370aaf53d149a /src
parentd29a389a40524c684595f51bb937f66958bc14ea (diff)
clip: Add support for wl-clipboard
Diffstat (limited to 'src')
-rwxr-xr-xsrc/password-store.sh26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/password-store.sh b/src/password-store.sh
index d89d455..284eabf 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -152,16 +152,32 @@ check_sneaky_paths() {
#
clip() {
+ if [[ -n $WAYLAND_DISPLAY ]]; then
+ local copy_cmd=( wl-copy )
+ local paste_cmd=( wl-paste -n )
+ if [[ $X_SELECTION == primary ]]; then
+ copy_cmd+=( --primary )
+ paste_cmd+=( --primary )
+ fi
+ local display_name="$WAYLAND_DISPLAY"
+ elif [[ -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"
+ fi
+ local sleep_argv0="password store sleep on display $display_name"
+
# 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" 2>/dev/null | $BASE64)"
- echo -n "$1" | xclip -selection "$X_SELECTION" || die "Error: Could not copy data to the clipboard"
+ local before="$("${paste_cmd[@]}" 2>/dev/null | $BASE64)"
+ echo -n "$1" | "${copy_cmd[@]}" || die "Error: Could not copy data to the clipboard"
(
( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '$CLIP_TIME' & wait" )
- local now="$(xclip -o -selection "$X_SELECTION" | $BASE64)"
+ local now="$("${paste_cmd[@]}" | $BASE64)"
[[ $now != $(echo -n "$1" | $BASE64) ]] && before="$now"
# It might be nice to programatically check to see if klipper exists,
@@ -173,7 +189,7 @@ clip() {
# so we axe it here:
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory &>/dev/null
- echo "$before" | $BASE64 -d | xclip -selection "$X_SELECTION"
+ echo "$before" | $BASE64 -d | "${copy_cmd[@]}"
) >/dev/null 2>&1 & disown
echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
}