refactor(clipboard): share provider detection across y/p/paste/hist
Extracts _fish_clipboard_copy and _fish_clipboard_paste so the wl-copy/xclip/win32yank fallback chain lives in one place instead of four near-duplicates. hist now goes through the same chain, so it also gets the xclip (X11) fallback it was missing before, alongside win32yank on WSL2.
This commit is contained in:
+5
-15
@@ -11,6 +11,9 @@
|
||||
# Copies text to the system clipboard using wl-copy (Wayland), xclip (X11),
|
||||
# or win32yank (WSL2). Reads from stdin when no arguments are given.
|
||||
#
|
||||
# DEPENDENCIES
|
||||
# _fish_clipboard_copy
|
||||
#
|
||||
# ARGUMENTS
|
||||
# text Text to copy; reads from stdin if omitted
|
||||
#
|
||||
@@ -36,26 +39,13 @@ function y --description 'Yank to clipboard'
|
||||
return 0
|
||||
end
|
||||
|
||||
# Determine the clipboard provider
|
||||
set -l copy_cmd
|
||||
if type -q wl-copy
|
||||
set copy_cmd wl-copy
|
||||
else if type -q xclip
|
||||
set copy_cmd xclip -selection clipboard
|
||||
else if type -q win32yank.exe
|
||||
set copy_cmd win32yank.exe -i --crlf
|
||||
else
|
||||
echo "Error: No clipboard provider (wl-copy, xclip, or win32yank) found." >&2
|
||||
return 1
|
||||
end
|
||||
|
||||
# Handle input
|
||||
if set -q argv[1]
|
||||
# If arguments are provided, echo them to the clipboard
|
||||
echo $argv | eval $copy_cmd
|
||||
echo $argv | _fish_clipboard_copy
|
||||
else
|
||||
# If no arguments, read from stdin (pipes/redirects)
|
||||
eval $copy_cmd
|
||||
_fish_clipboard_copy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user