fish_clipboard_{copy,paste}: only use xsel/xclip if $DISPLAY is set

Ubuntu's fish package on WSL 1 has xsel as recommended dependency,
even though there is no X server available.  This change makes us
use Windows' native clipboard even when xsel is installed.
This commit is contained in:
Johannes Altmanninger 2021-07-23 20:50:04 +02:00
parent 938879a85a
commit 72fd328ad2
2 changed files with 8 additions and 10 deletions

View File

@ -6,12 +6,10 @@ function fish_clipboard_copy
printf '%s' $cmdline | pbcopy
else if set -q WAYLAND_DISPLAY; and type -q wl-copy
printf '%s' $cmdline | wl-copy
else if type -q xsel
# Silence error so no error message shows up
# if e.g. X isn't running.
printf '%s' $cmdline | xsel --clipboard 2>/dev/null
else if type -q xclip
printf '%s' $cmdline | xclip -selection clipboard 2>/dev/null
else if set -q DISPLAY; and type -q xsel
printf '%s' $cmdline | xsel --clipboard
else if set -q DISPLAY; and type -q xclip
printf '%s' $cmdline | xclip -selection clipboard
else if type -q clip.exe
printf '%s' $cmdline | clip.exe
end

View File

@ -4,10 +4,10 @@ function fish_clipboard_paste
set data (pbpaste 2>/dev/null)
else if set -q WAYLAND_DISPLAY; and type -q wl-paste
set data (wl-paste 2>/dev/null)
else if type -q xsel
set data (xsel --clipboard 2>/dev/null)
else if type -q xclip
set data (xclip -selection clipboard -o 2>/dev/null)
else if set -q DISPLAY; and type -q xsel
set data (xsel --clipboard)
else if set -q DISPLAY; and type -q xclip
set data (xclip -selection clipboard -o)
else if type -q powershell.exe
set data (powershell.exe Get-Clipboard | string trim -r -c \r)
end