Files
fish-config/functions/y.fish
T
rootiest 07613c7889 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.
2026-09-21 02:44:12 -04:00

76 lines
2.1 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 09-clipboard
#
# SYNOPSIS
# y [text...]
#
# DESCRIPTION
# 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
#
# EXIT STATUS
# 0 Text copied to clipboard
# 1 No clipboard provider found
#
# EXAMPLE
# y "hello world"
# ls | y
# cat file.txt | y
function y --description 'Yank to clipboard'
# Check for help flag
if contains -- -h $argv; or contains -- --help $argv
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""y$c_reset $c_arg""[TEXT]$c_reset or $c_arg""[COMMAND]$c_reset | $c_cmd""y$c_reset"
echo ""
echo "$c_head""Examples:$c_reset"
echo " $c_cmd""y$c_reset \"hello world\" "$c_dim"Copy a string directly"$c_reset
echo " ls | $c_cmd""y$c_reset "$c_dim"Copy output of a command"$c_reset
echo " $c_cmd""y$c_reset < file.txt "$c_dim"Copy contents of a file"$c_reset
echo " cat file.txt | $c_cmd""y$c_reset "$c_dim"Another way to copy a file"$c_reset
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
else
# If no arguments, read from stdin (pipes/redirects)
eval $copy_cmd
end
end
# SYNOPSIS
# cb [text...]
#
# DESCRIPTION
# Alias for y — copies text to the system clipboard.
#
# ARGUMENTS
# text Text to copy; reads from stdin if omitted
#
# EXAMPLE
# ls | cb
function cb --wraps='y' --description 'Alias cb=y'
y $argv
end