From 07613c7889003c002c2fec17db0d2cde04d3a71d Mon Sep 17 00:00:00 2001 From: Rootiest Date: Mon, 21 Sep 2026 02:43:50 -0400 Subject: [PATCH] feat(clipboard): add win32yank fallback for WSL2 y, p, paste, and hist now try win32yank.exe after wl-copy/wl-paste and xclip, so clipboard access works under WSL2 once win32yank is installed and reachable through WSL interop. Updates the OS compatibility docs accordingly. --- .../04-c4-terminal-and-tool-integration.md | 2 +- docs/manual/10-installation.md | 15 +++++++++------ functions/hist.fish | 9 +++++++-- functions/p.fish | 8 +++++--- functions/paste.fish | 8 +++++--- functions/y.fish | 8 +++++--- 6 files changed, 32 insertions(+), 18 deletions(-) diff --git a/docs/manual/08-components-reference/04-c4-terminal-and-tool-integration.md b/docs/manual/08-components-reference/04-c4-terminal-and-tool-integration.md index 952df73..c064439 100644 --- a/docs/manual/08-components-reference/04-c4-terminal-and-tool-integration.md +++ b/docs/manual/08-components-reference/04-c4-terminal-and-tool-integration.md @@ -13,7 +13,7 @@ These features couple the shell to specific external tools. Disabling spwin Kitty or WezTerm tab Kitty, WezTerm, or Konsole split Kitty or WezTerm - hist fzf + wl-copy (Wayland clipboard) + hist fzf + wl-copy or win32yank.exe (WSL2) logs fzf + ov; reads from ~/.terminal_history/ upgrade paru or yay (Arch Linux only) WakaTime hook wakatime CLI and a configured API key diff --git a/docs/manual/10-installation.md b/docs/manual/10-installation.md index 85f5e60..0d7280e 100644 --- a/docs/manual/10-installation.md +++ b/docs/manual/10-installation.md @@ -35,11 +35,14 @@ no fallback: - `systemd-inhibit` (`wake-lock`) - `zramctl` / `swapon` (`swapstat`) - `sbctl` and UEFI Secure Boot state (`sbver`) -- `wl-copy` / `xclip` for clipboard access (`y`, `p`, `paste`, `hist`) — - Wayland or X11 only, no `pbcopy`/`pbpaste` fallback - GNU coreutils flags such as `stat -c` and `numfmt` (`sudo-toggle`, `dng2avif`), which differ or don't exist under a BSD userland +Clipboard access (`y`, `p`, `paste`, `hist`) is the exception: it falls back +through `wl-copy`/`wl-paste` (Wayland), `xclip` (X11), and `win32yank.exe` +(WSL2), so it works on all three. There is still no `pbcopy`/`pbpaste` +fallback for macOS. + **macOS** is not supported. `_fish_deps_detect_pm` does check for `brew`, but that alone does not make the functions above work — they have no macOS equivalent path today. @@ -47,10 +50,10 @@ equivalent path today. **Windows** is not supported. Fish itself has no native Windows build; upstream's own "Windows" install docs are Cygwin/WSL workarounds, not a real port. This config is not tested under WSL either. WSL2 runs a real Linux -kernel and can run `systemd`, so basic shell use may work, but `zramctl`, -`sbctl`, and Secure Boot state are meaningless inside a VM, and clipboard -integration would need a WSL-specific path (`clip.exe`, `win32yank`) that -does not exist here. +kernel and can run `systemd`, so basic shell use may work; `zramctl`, +`sbctl`, and Secure Boot state are still meaningless inside a VM, but +clipboard integration works via `win32yank.exe` (see above) once it's +installed on the Windows side and reachable through WSL interop. **Assumed present on any Linux system this runs on:** `git`, `gpg`, `tar`, and GNU coreutils (for `stat`, `date`, `numfmt`). These are not tracked by diff --git a/functions/hist.fish b/functions/hist.fish index a23a3fd..bc6fcd3 100644 --- a/functions/hist.fish +++ b/functions/hist.fish @@ -12,7 +12,8 @@ # # DESCRIPTION # Searches fish history interactively using fzf, inserts the selected command -# into the command line, and copies it to the clipboard via wl-copy. +# into the command line, and copies it to the clipboard via wl-copy (falls +# back to win32yank on WSL2). # # EXIT STATUS # 0 Command selected and inserted, or fzf was cancelled @@ -36,7 +37,11 @@ function hist --description 'Search fish history and put it in the prompt' # Strip the timestamp for the final output set -l command (echo $selected | string replace -r '^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} ' '') - echo $command | wl-copy 2>/dev/null + if type -q wl-copy + echo $command | wl-copy 2>/dev/null + else if type -q win32yank.exe + echo $command | win32yank.exe -i --crlf 2>/dev/null + end commandline -r $command end end diff --git a/functions/p.fish b/functions/p.fish index 2c5562a..20e4f42 100644 --- a/functions/p.fish +++ b/functions/p.fish @@ -8,8 +8,8 @@ # p [args...] # # DESCRIPTION -# Outputs clipboard contents to stdout. Uses wl-paste on Wayland, -# falls back to xclip on X11. Supports -h/--help for usage info. +# Outputs clipboard contents to stdout. Uses wl-paste on Wayland, xclip on +# X11, or win32yank on WSL2. Supports -h/--help for usage info. # # ARGUMENTS # -h, --help Show usage help @@ -47,8 +47,10 @@ function p --description 'Put from clipboard' 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 or xclip) found." >&2 + echo "Error: No clipboard provider (wl-paste, xclip, or win32yank) found." >&2 return 1 end diff --git a/functions/paste.fish b/functions/paste.fish index 33f6e45..f48ffed 100644 --- a/functions/paste.fish +++ b/functions/paste.fish @@ -8,8 +8,8 @@ # paste [args...] # # DESCRIPTION -# Outputs clipboard contents to stdout. Uses wl-paste on Wayland, -# falls back to xclip on X11. +# Outputs clipboard contents to stdout. Uses wl-paste on Wayland, xclip on +# X11, or win32yank on WSL2. # # ARGUMENTS # args... Arguments forwarded to the clipboard tool @@ -28,8 +28,10 @@ function paste --description 'Paste from clipboard' wl-paste $argv else if type -q xclip xclip -selection clipboard -o $argv + else if type -q win32yank.exe + win32yank.exe -o --lf $argv else - echo "Error: Neither wl-paste nor xclip found." >&2 + echo "Error: No clipboard provider (wl-paste, xclip, or win32yank) found." >&2 return 1 end end diff --git a/functions/y.fish b/functions/y.fish index 1b862df..43c2723 100644 --- a/functions/y.fish +++ b/functions/y.fish @@ -8,8 +8,8 @@ # y [text...] # # DESCRIPTION -# Copies text to the system clipboard using wl-copy (Wayland) or xclip (X11). -# Reads from stdin when no arguments are given. +# Copies text to the system clipboard using wl-copy (Wayland), xclip (X11), +# or win32yank (WSL2). Reads from stdin when no arguments are given. # # ARGUMENTS # text Text to copy; reads from stdin if omitted @@ -42,8 +42,10 @@ function y --description 'Yank to clipboard' 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 or xclip) found." >&2 + echo "Error: No clipboard provider (wl-copy, xclip, or win32yank) found." >&2 return 1 end