Files
fish-config/functions/p.fish
T
rootiest b2be858d8c 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.
2026-09-21 02:52:17 -04:00

49 lines
1.4 KiB
Fish

# Copyright (C) 2026 Rootiest
# SPDX-License-Identifier: AGPL-3.0-or-later
# CATEGORY
# 09-clipboard
#
# SYNOPSIS
# p [args...]
#
# DESCRIPTION
# 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
#
# EXIT STATUS
# 0 Clipboard contents read successfully
# 1 No supported clipboard tool found
#
# RETURNS
# The clipboard contents, printed to stdout
#
# EXAMPLE
# p | grep foo
# p > file.txt
function p --description 'Put from clipboard'
# Check for help flag
if contains -- -h $argv; or contains -- --help $argv
__fish_palette
echo "$c_head""Usage:$c_reset $c_cmd""p$c_reset $c_flag""[OPTIONS]$c_reset"
echo ""
echo " Pastes content from the system clipboard to stdout."
echo ""
echo "$c_head""Examples:$c_reset"
echo " $c_cmd""p$c_reset "$c_dim"Print clipboard content"$c_reset
echo " $c_cmd""p$c_reset > file.txt "$c_dim"Save clipboard to a file"$c_reset
echo " $c_cmd""p$c_reset | grep 'foo' "$c_dim"Pipe clipboard content to another command"$c_reset
echo " cat ($c_cmd""p$c_reset) "$c_dim"Use clipboard content as a filename for cat"$c_reset
return 0
end
_fish_clipboard_paste $argv
end