fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
ab39fab68
master
1function fish_clipboard_copy 2set -l cmdline 3if isatty stdin 4# Copy the current selection, or the entire commandline if that is empty. 5# Don't use `string collect -N` here - `commandline` adds a newline. 6set cmdline( commandline --current-selection| fish_indent --only-indent| string collect) 7test -n " $cmdline " ;or set cmdline( commandline | fish_indent --only-indent| string collect) 8else 9# Read from stdin 10while read -lz line 11set -a cmdline$line 12end 13end 14 15if type -q pbcopy 16printf '%s' $cmdline | pbcopy 17else if set -q WAYLAND_DISPLAY;and type -q wl-copy 18printf '%s' $cmdline | wl-copy & 19disown 20else if set -q DISPLAY;and type -q xsel 21printf '%s' $cmdline | xsel --clipboard 22else if set -q DISPLAY;and type -q xclip 23printf '%s' $cmdline | xclip -selection clipboard 24else if type -q clip.exe 25printf '%s' $cmdline | clip.exe 26end 27 28# Copy with OSC 52; useful if we are running in an SSH session or in 29# a container. 30if type -q base64&& [ " $TERM " != dumb] 31if not isatty stdout 32echo "fish_clipboard_copy: stdout is not a terminal" >&2 33return 1 34end 35set -l encoded( printf %s$cmdline | base64 | string join'' ) 36printf '\e]52;c;%s\a' " $encoded " 37# tmux requires user configuration to interpret OSC 52 on stdout. 38# Luckily we can still make this work for the common case by bypassing 39# tmux and writing to its underlying terminal. 40if set -q TMUX 41set -l tmux_tty( tmux display-message -p'#{client_tty}' ) 42or return 1 43# The terminal might not be writable if we switched user. 44if test -w $tmux_tty 45printf '\e]52;c;%s\a' " $encoded " > $tmux_tty 46end 47end 48end 49end