Skip to content

Instantly share code, notes, and snippets.

@rootiest
Last active April 26, 2026 03:57
Show Gist options
  • Select an option

  • Save rootiest/1ec40bddcef1ee4ae413665add7315ce to your computer and use it in GitHub Desktop.

Select an option

Save rootiest/1ec40bddcef1ee4ae413665add7315ce to your computer and use it in GitHub Desktop.
Fish Copy/Paste utility functions (requires wl-copy or xclip package installed)
function p --description 'Put from clipboard'
# Check for help flag
if contains -- -h $argv; or contains -- --help $argv
echo "Usage: p [OPTIONS]"
echo ""
echo "Description:"
echo " Pastes content from the system clipboard to stdout."
echo ""
echo "Examples:"
echo " p Print clipboard content"
echo " p > file.txt Save clipboard to a file"
echo " p | grep 'foo' Pipe clipboard content to another command"
echo " cat (p) Use clipboard content as a filename for cat"
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
echo "Error: No clipboard provider (wl-paste or xclip) found." >&2
return 1
end
# Execute the paste command with any provided arguments
$paste_cmd $argv
end
function y --description 'Yank to clipboard'
# Check for help flag
if contains -- -h $argv; or contains -- --help $argv
echo "Usage: y [TEXT] or [COMMAND] | y"
echo ""
echo "Examples:"
echo " y \"hello world\" Copy a string directly"
echo " ls | y Copy output of a command"
echo " y < file.txt Copy contents of a file"
echo " cat file.txt | y Another way to copy a file"
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
echo "Error: No clipboard provider (wl-copy or xclip) 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment