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:
2026-09-21 02:52:17 -04:00
parent 07613c7889
commit b2be858d8c
7 changed files with 79 additions and 48 deletions
+4 -15
View File
@@ -11,6 +11,9 @@
# Outputs clipboard contents to stdout. Uses wl-paste on Wayland, xclip on
# X11, or win32yank on WSL2. Supports -h/--help for usage info.
#
# DEPENDENCIES
# _fish_clipboard_paste
#
# ARGUMENTS
# -h, --help Show usage help
# args... Arguments forwarded to the clipboard tool
@@ -41,19 +44,5 @@ function p --description 'Put from clipboard'
return 0
end
# Determine the clipboard provider
set -l paste_cmd
if type -q wl-paste
set paste_cmd wl-paste
else if type -q xclip
set paste_cmd xclip -selection clipboard -o
else if type -q win32yank.exe
set paste_cmd win32yank.exe -o --lf
else
echo "Error: No clipboard provider (wl-paste, xclip, or win32yank) found." >&2
return 1
end
# Execute the paste command with any provided arguments
$paste_cmd $argv
_fish_clipboard_paste $argv
end