Total Posts

0

Total Commits

0

(v1: 0, v2: 0)
Total Deployments

0

Latest commit:Unable to fetch commit info
7/9/2025
Latest deployment:
pending
7/9/2025
v2
Started 7/9/2025

Built by Remco Stoeten with a little ❤️

Snippets.remcostoeten
Snippets.remcostoeten
Snippets
Welcome to Snippets
Cleanup enviorment
Clipboard Copy Commands
Fish Shell Port and File Utilities
Recursive file & folder creation
Dotfiles/Scripts

Clipboard Copy Commands

A set of functions to simplify copying to the clipboard in the terminal.

Clipboard Copy Commands

A set of functions to simplify copying to the clipboard in the terminal.

🔑

This file adds copy and copypwd functions to your Fish shell. It's designed for fast CLI clipboard workflows and includes a smart help menu with colorized output.

⚠️

Ensure xclip is installed, as it's required for copying to your system clipboard.

Installation

Place the script in your shell config directory (e.g., ~/.config/fish/functions/clipboard) and source it from your main config:

👨‍💻echo 'source ~/.config/fish/functions/clipboard' >> ~/.config/fish/config.fish

It will remain silent when sourced.

Usage

🧪 Copy current working directory

copypwd

📋 Will copy: /current/path/you/are/in


🧪 Copy a full path to a file

copypwd ./myfile.ts

📋 Will copy: /full/path/to/myfile.ts


🧪 Copy a file's contents

copy myfile.txt

📋 If the file contains "hello world", this string will be copied to the clipboard.


🧪 Show the colorized help menu

Any of the following commands will show the help menu:

copy --help

⏹️ Recognized aliases: copy, copy -h, copy --h, copy help, copy -help, copy --help

Full Source Code

##!/usr/bin/env fish
 
# A silent sourceable clipboard helper for Fish shell
# Adds `copy`, `copypwd`, and a built-in colorized help menu
 
function copy
  set -l arg1 $argv[1]
  set -l arg2 $argv[2]
 
  if test (count $argv) -eq 0
    echo -e (set_color yellow)"✦ No arguments provided. Type "(set_color cyan)"copy --help"(set_color yellow)" for usage."
    return 1
  end
 
  switch $arg1
    case "help" "-h" "--h" "-help" "--help"
      echo ""
      echo -e (set_color brmagenta)"╭──────────────────────────────────────────────╮"
      echo -e (set_color brmagenta)"│"(set_color green)"         Fish Clipboard Helper v1.0        "(set_color brmagenta)"│"
      echo -e (set_color brmagenta)"╰──────────────────────────────────────────────╯"
      echo ""
      echo -e (set_color cyan)"Commands:"
      echo -e (set_color green)"  copy [file]"(set_color normal)"         → Copies the contents of a file"
      echo -e (set_color green)"  copypwd"(set_color normal)"            → Copies the current working directory"
      echo -e (set_color green)"  copypwd [file]"(set_color normal)"     → Copies full absolute path to file"
      echo ""
      echo -e (set_color cyan)"Help Aliases:"
      echo -e (set_color yellow)"  help, -h, --h, -help, --help"
      echo ""
      return 0
 
    case "pwd"
      if test -n "$arg2"
        set -l abs (realpath "$arg2" ^/dev/null)
        if test -e "$abs"
          echo -n "$abs" | xclip -selection clipboard
          echo -e (set_color green)"✓ Copied:"(set_color normal)" $abs"
        else
          echo -e (set_color red)"✗ File not found:"(set_color normal)" $arg2"
        end
      else
        echo -n (pwd) | xclip -selection clipboard
        echo -e (set_color green)"✓ Copied current directory to clipboard."
      end
      return 0
 
    case '*'
      if test -f "$arg1"
        cat "$arg1" | xclip -selection clipboard
        echo -e (set_color green)"✓ Copied contents of file:"(set_color normal)" $arg1"
      else
        echo -e (set_color red)"✗ File not found:"(set_color normal)" $arg1"
      end
  end
end
 
function copypwd
  if test (count $argv) -eq 0
    echo -n (pwd) | xclip -selection clipboard
    echo -e (set_color green)"✓ Copied current directory."
  else
    set -l abs (realpath "$argv[1]" ^/dev/null)
    if test -e "$abs"
      echo -n "$abs" | xclip -selection clipboard
      echo -e (set_color green)"✓ Copied full path to:"(set_color normal)" $abs"
    else
      echo -e (set_color red)"✗ File not found:"(set_color normal)" $argv[1]"
    end
  end
end

Cleanup enviorment

Cleans up generated development files based on if it's a nextjs or vite app

Fish Shell Port and File Utilities

A set of Fish shell functions to list listening ports, interactively kill processes by port, and create timestamped file backups.

On this page

InstallationUsageFull Source Code
Jul 9, 2025
5 min read
878 words