From 7eb039914c8819e2b7c665db81dbaed73075dbdf Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 5 Sep 2022 11:04:04 +0200 Subject: fish: add wayland support to pp --- config/fish/functions/pp.fish | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'config/fish/functions/pp.fish') 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 -- cgit v1.2.3