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 c064439..8f94b7d 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 or win32yank.exe (WSL2) + hist fzf + wl-copy, xclip, 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/functions/_fish_clipboard_copy.fish b/functions/_fish_clipboard_copy.fish new file mode 100644 index 0000000..0d4c3e1 --- /dev/null +++ b/functions/_fish_clipboard_copy.fish @@ -0,0 +1,28 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# SYNOPSIS +# _fish_clipboard_copy +# +# DESCRIPTION +# Copies stdin to the system clipboard. Tries wl-copy (Wayland), then +# xclip (X11), then win32yank.exe (WSL2). +# +# EXIT STATUS +# 0 Text copied to clipboard +# 1 No clipboard provider found +# +# EXAMPLE +# echo "hello" | _fish_clipboard_copy +function _fish_clipboard_copy --description 'Copy stdin to the system clipboard' + if type -q wl-copy + wl-copy + else if type -q xclip + xclip -selection clipboard + else if type -q win32yank.exe + win32yank.exe -i --crlf + else + echo "Error: No clipboard provider (wl-copy, xclip, or win32yank) found." >&2 + return 1 + end +end diff --git a/functions/_fish_clipboard_paste.fish b/functions/_fish_clipboard_paste.fish new file mode 100644 index 0000000..1b05710 --- /dev/null +++ b/functions/_fish_clipboard_paste.fish @@ -0,0 +1,31 @@ +# Copyright (C) 2026 Rootiest +# SPDX-License-Identifier: AGPL-3.0-or-later + +# SYNOPSIS +# _fish_clipboard_paste [args...] +# +# DESCRIPTION +# Prints the system clipboard contents to stdout. Tries wl-paste +# (Wayland), then xclip (X11), then win32yank.exe (WSL2). +# +# ARGUMENTS +# args... Arguments forwarded to the clipboard tool +# +# EXIT STATUS +# 0 Clipboard contents read successfully +# 1 No clipboard provider found +# +# EXAMPLE +# _fish_clipboard_paste +function _fish_clipboard_paste --description 'Print the system clipboard contents' + if type -q wl-paste + 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: No clipboard provider (wl-paste, xclip, or win32yank) found." >&2 + return 1 + end +end diff --git a/functions/hist.fish b/functions/hist.fish index bc6fcd3..c0b7c7a 100644 --- a/functions/hist.fish +++ b/functions/hist.fish @@ -12,8 +12,11 @@ # # DESCRIPTION # Searches fish history interactively using fzf, inserts the selected command -# into the command line, and copies it to the clipboard via wl-copy (falls -# back to win32yank on WSL2). +# into the command line, and copies it to the clipboard via wl-copy, xclip, +# or win32yank (WSL2). +# +# DEPENDENCIES +# _fish_clipboard_copy # # EXIT STATUS # 0 Command selected and inserted, or fzf was cancelled @@ -37,11 +40,7 @@ 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} ' '') - 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 + echo $command | _fish_clipboard_copy 2>/dev/null commandline -r $command end end diff --git a/functions/p.fish b/functions/p.fish index 20e4f42..9ce4ef9 100644 --- a/functions/p.fish +++ b/functions/p.fish @@ -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 diff --git a/functions/paste.fish b/functions/paste.fish index f48ffed..9e7375a 100644 --- a/functions/paste.fish +++ b/functions/paste.fish @@ -11,6 +11,9 @@ # Outputs clipboard contents to stdout. Uses wl-paste on Wayland, xclip on # X11, or win32yank on WSL2. # +# DEPENDENCIES +# _fish_clipboard_paste +# # ARGUMENTS # args... Arguments forwarded to the clipboard tool # @@ -24,14 +27,5 @@ # EXAMPLE # paste > file.txt function paste --description 'Paste from clipboard' - if type -q wl-paste - 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: No clipboard provider (wl-paste, xclip, or win32yank) found." >&2 - return 1 - end + _fish_clipboard_paste $argv end diff --git a/functions/y.fish b/functions/y.fish index 43c2723..8edf6d0 100644 --- a/functions/y.fish +++ b/functions/y.fish @@ -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