fish_clipboard_copy: Use selection, if any

See #5368.
This commit is contained in:
Fabian Homborg 2018-11-25 17:32:25 +01:00
parent d065ff840d
commit 20099774a0

View File

@ -1,11 +1,14 @@
function fish_clipboard_copy
# Copy the current selection, or the entire commandline if that is empty.
set -l cmdline (commandline --current-selection)
test -n "$cmdline"; or set cmdline (commandline)
if type -q pbcopy
commandline | pbcopy
printf '%s\n' $cmdline | pbcopy
else if type -q xsel
# Silence error so no error message shows up
# if e.g. X isn't running.
commandline | xsel --clipboard 2>/dev/null
printf '%s\n' $cmdline | xsel --clipboard 2>/dev/null
else if type -q xclip
commandline | xclip -selection clipboard 2>/dev/null
printf '%s\n' $cmdline | xclip -selection clipboard 2>/dev/null
end
end