aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/fish/functions/pp.fish34
1 files changed, 22 insertions, 12 deletions
diff --git a/config/fish/functions/pp.fish b/config/fish/functions/pp.fish
index 6cd9161..6f25d78 100644
--- a/config/fish/functions/pp.fish
+++ b/config/fish/functions/pp.fish
@@ -1,17 +1,27 @@
function pp --description 'safely execute content from the clipboard'
# fish version of https://github.com/Aaronmsv/PastejackingProtection
-
- if not type -q xclip
- echo please install xclip
- return
- end
- set script (xclip -o)
- echo "$script" | cat -A
- echo -e "\nExecute? (y/N): "
- read execute
+ if set -q WAYLAND_DISPLAY
+ set -f clip_cmd wl-paste
+ else if set -q DISPLAY
+ set -f clip_cmd "xclip -o"
+ else
+ echo "No graphical session detected" >&2
+ return 1
+ end
- if test "$execute" = "y"
- eval $script
- end
+ set -f clip_exe (string split -f 1 " " $clip_cmd)
+ if not type -q (string split -f 1 " " $clip_exe)
+ echo "please install $clip_exe" >&2
+ return 1
+ end
+
+ set -f script ($clip_cmd)
+ echo "$script" | cat -A
+ echo -e "\nExecute? (y/N): "
+ read execute
+
+ if test "$execute" = "y"
+ eval $script
+ end
end