Skip to main content

Overview

The clip command reads content from standard input (stdin) and copies it to your system clipboard. It’s perfect for capturing command output, file contents, or piped data for easy pasting.

Syntax

<command> | ahh clip

Parameters

This command takes no parameters. It reads all input from stdin.

Usage Examples

# Copy the output of ls
ls -la | ahh clip

# Copy git status
git status | ahh clip

# Copy current directory path
pwd | ahh clip

Output

When successful, the command displays:
Copied to clipboard.

How It Works

Stdin Reading

The command:
  1. Waits for stdin input (blocks if no input is piped)
  2. Reads all available stdin content
  3. Passes the content to the system clipboard
  4. Confirms the operation

Clipboard Integration

Uses the copy-paste npm package which:
  • Detects your operating system
  • Uses the appropriate clipboard mechanism:
    • macOS: pbcopy
    • Linux: xclip or xsel
    • Windows: clip

Platform Requirements

macOS

Works out of the box. Uses the built-in pbcopy command.

Linux

Requires xclip or xsel to be installed.
Install on Ubuntu/Debian:
sudo apt-get install xclip
Install on Fedora/RHEL:
sudo dnf install xclip

Windows

Uses the built-in clip command. Works out of the box.

Common Patterns

Debugging

# Copy error output for sharing
npm run build 2>&1 | ahh clip

# Copy test failures
pytest 2>&1 | ahh clip

Configuration Sharing

# Copy SSH public key
cat ~/.ssh/id_rsa.pub | ahh clip

# Copy environment variables
env | ahh clip

# Copy network configuration
ifconfig | ahh clip

Code Sharing

# Copy a function from a file
grep -A 20 "function myFunc" script.js | ahh clip

# Copy all imports from a file
grep "^import" src/index.ts | ahh clip

Data Processing

# Copy processed data
cat data.csv | cut -d',' -f1,3 | ahh clip

# Copy sorted unique values
cat list.txt | sort | uniq | ahh clip

Technical Details

Implementation

The command uses:
  • copy-paste library for cross-platform clipboard access
  • Bun’s stdin reading utilities
  • Synchronous clipboard operation

Stdin Reading

The stdin content is read using:
const input = await getStdin();
This function:
  • Reads from process.stdin
  • Waits for EOF (End of File)
  • Returns the complete input as a string

Error Handling

No Stdin Input

If you run the command without piping input:
ahh clip
The command will wait indefinitely for input. Press Ctrl+D (Unix) or Ctrl+Z (Windows) to signal EOF.

Clipboard Access Errors

If clipboard access fails (missing dependencies on Linux):
  • The command may throw an error
  • Install the required clipboard utility for your platform

Notes

The entire stdin is read into memory before copying. For very large inputs, this may consume significant memory.
The clipboard content persists after the command exits, allowing you to paste it anywhere.
  • qr - Generate QR codes from stdin
  • share-discord - Share stdin content to Discord

Build docs developers (and LLMs) love