mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-04-30 01:11:14 -03:00
If fish is invoked as
execve("/bin/fish", "fish")
on OpenBSD, "status fish-path" will output "fish". As a result,
our wrapper for fish_indent tries to execute "./fish" if it exists.
We actually no longer need to call any executable, since "fish_indent"
is available as builtin now.
Stop using the wrapper, fixing the OpenBSD issue.
50 lines
1.9 KiB
Fish
50 lines
1.9 KiB
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 | fish_indent --only-indent | string collect)
|
|
test -n "$cmdline"; or set cmdline (commandline | fish_indent --only-indent | 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 &
|
|
disown
|
|
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
|
|
|
|
# Copy with OSC 52; useful if we are running in an SSH session or in
|
|
# a container.
|
|
if type -q base64 && [ "$TERM" != dumb ]
|
|
if not isatty stdout
|
|
echo "fish_clipboard_copy: stdout is not a terminal" >&2
|
|
return 1
|
|
end
|
|
set -l encoded (printf %s $cmdline | base64 | string join '')
|
|
printf '\e]52;c;%s\a' "$encoded"
|
|
# tmux requires user configuration to interpret OSC 52 on stdout.
|
|
# Luckily we can still make this work for the common case by bypassing
|
|
# tmux and writing to its underlying terminal.
|
|
if set -q TMUX
|
|
set -l tmux_tty (tmux display-message -p '#{client_tty}')
|
|
or return 1
|
|
# The terminal might not be writable if we switched user.
|
|
if test -w $tmux_tty
|
|
printf '\e]52;c;%s\a' "$encoded" >$tmux_tty
|
|
end
|
|
end
|
|
end
|
|
end
|