mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 22:03:12 +00:00
29778ee845
This makes these tools usable in a pipe. You can run ```fish some-long-command | fish_clipboard_copy ``` to copy some command's output to your clipboard, and ```fish fish_clipboard_paste | some-other-command ``` To feed your clipboard to some command.
26 lines
922 B
Fish
26 lines
922 B
Fish
function fish_clipboard_copy
|
|
set -l cmdline
|
|
if isatty stdin
|
|
# Copy the current selection, or the entire commandline if that is empty.
|
|
# Don't use `string collect -N` here - `commandline` adds a newline.
|
|
set cmdline (commandline --current-selection | string collect)
|
|
test -n "$cmdline"; or set cmdline (commandline | string collect)
|
|
else
|
|
# Read from stdin
|
|
while read -lz line
|
|
set -a cmdline $line
|
|
end
|
|
end
|
|
|
|
if type -q pbcopy
|
|
printf '%s' $cmdline | pbcopy
|
|
else if set -q WAYLAND_DISPLAY; and type -q wl-copy
|
|
printf '%s' $cmdline | wl-copy
|
|
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
|
|
end
|