xcat is a feature-packed, dependency-light Bash utility that copies files, stdin, or directory contents to your clipboard — with optional line ranges, preview, compression, verification, and backend autodetection.
It’s made for those “show me the exact lines you’re talking about” moments: logs, snippets, configs, or code blocks — with safety, style, and speed.
- 📋 Copy to clipboard from:
- A file
- Several files at once (each prefixed with its path)
- Standard input (pipes) — omit the argument or pass
- - All regular files in a directory (non-recursive)
- 🔢 Optional line ranges:
-s START/-e END(1-based, inclusive)-L START:ENDshorthand (either side can be omitted)
- 🖥️ Auto-detects clipboard backend:
xclip(X11)wl-copy/wl-clipboard(Wayland)pbcopy(macOS)clip.exe(WSL)
- 📦 Optional install of clipboard tools with
--installusing:apt-get,dnf,yum,pacman,zypper, orbrew- (opt-in only — xcat never runs
sudounless you ask it to)
- 🧱 Directory mode:
- Non-recursive
- Concatenates all regular text files
- Supports
--types=ext1,ext2filters - Prefixes each chunk with its full path
- 🧠 Advanced options:
--preview— syntax-highlight preview (withbatorbatcat)--verify— show clipboard contents after copy--compress— gzip + base64 encode payloads before copying--tee— print and copy simultaneously--backend=NAME— override autodetection--list-backends— show available backends--check-update— check GitHub for a newer version--update— pull the latest xcat and replace this file in place--quiet/--verbose— control output--version— print version info
- 🛡️ Safety features:
- Detects and refuses binary input
- Validates numeric options
- Uses
set -euo pipefail - Clear, colored messages for feedback
- 🧮 Integrity & info:
- Shows SHA-1 checksum of copied payload
- Reports compression and line range info
- Bash ≥ 4.0
- One of the following clipboard utilities:
- Linux / BSD:
xclip(X11) orwl-clipboard(Wayland) - macOS:
pbcopy - WSL:
clip.exe
- Linux / BSD:
If none are available, xcat prints manual install instructions. Pass
--install to let it install xclip or wl-clipboard for you via your system
package manager (this runs sudo).
sudo curl -L https://raw.githubusercontent.com/WebWalker3D/Xcat/main/xcat \
-o /usr/local/bin/xcat
sudo chmod +x /usr/local/bin/xcatVerify it’s working:
xcat -hYou should see the usage help.
xcat [OPTIONS] [FILE]-
If
FILEis omitted,xcatreads from stdin. -
If
FILEis a directory, it:- Concatenates all regular text files (non-recursively)
- Optionally filters by extension via
--types= - Prefixes each section with its full path
- Sends the combined output to your clipboard
| Option | Description |
|---|---|
-s START |
1-based start line (inclusive) |
-e END |
1-based end line (inclusive) |
-L A:B |
Shorthand line range (-L 10:20, -L 15:, -L :50) |
-p, --preview |
Show syntax-highlighted preview (requires bat or batcat) |
--verify |
Print first 10 lines of clipboard after copying |
--compress |
gzip + base64 encode payload before copying |
--tee |
Print output to stdout and clipboard simultaneously |
--install |
Allow xcat to install a backend if none is found (runs sudo) |
--backend=NAME |
Force backend (xclip, wl-copy, pbcopy, clip.exe) |
--types=ext1,ext2 |
Limit directory mode to specific file types |
--check-update |
Check GitHub for a newer version and report (no changes) |
--update |
Download the latest xcat and replace this file in place |
--list-backends |
Show available clipboard backends and exit |
-q, --quiet |
Suppress non-error output |
-v, --verbose |
Show backend and diagnostic info |
-V, --version |
Print version info and exit |
-h, --help |
Show usage help and exit |
Numeric options are validated; START and END must be positive integers (≥ 1), and END cannot be less than START.
Note: options must come before the file argument(s) —
xcat --verify file, notxcat file --verify. Line ranges apply only to a single file or stdin, not to directories or multiple files.
xcat ~/.bashrcxcat main.c util.c util.h # each section prefixed with its pathxcat -s 10 -e 30 app.log
xcat -L 15: app.log
xcat -L :50 app.loggrep ERROR app.log | xcat -L :50
kubectl get pods -A | xcatxcat /etc/apache2/sites-available/Filter by extension:
xcat /etc --types=conf,servicexcat -p --verify app.logxcat --compress large.txtxcat --backend=wl-copy myfile.txtxcat --tee script.sh | wc -lxcat --list-backendsOn first run, xcat tries the following in order:
xclip -selection clipboardwl-copypbcopyclip.exe
If none are available, xcat prints clear manual install instructions and exits.
If you pass --install, it will instead try to install a backend for you:
-
Detects Wayland vs X11
-
Installs the matching tool via your package manager (runs
sudo):wl-clipboard(for Wayland)xclip(for X11)
-
Supported managers:
apt-get,dnf,yum,pacman,zypper,brew
Without --install, xcat never runs sudo or touches your package manager.
| Code | Meaning |
|---|---|
0 |
Success |
1 |
Runtime failure (e.g. file not found, no clipboard backend) |
2 |
Invalid usage (bad options, non-numeric values, etc.) |
Each successful copy displays:
- SHA-1 checksum of the payload
- Optional compression and range info
- Active clipboard backend (in verbose mode)
- Works beautifully with
grep,rg,sed,awk, etc. - Great over SSH with X11 forwarding or WSL clipboard bridges. (Original use case was copying text files over SSH)
- Safe with binary detection — won’t copy executables accidentally.
- Directory mode +
--typesis handy for aggregating config files. - Combine with
fzforbatfor interactive snippet sharing. - Designed to be portable, predictable, and copy-ready anywhere.
xcat can update itself from GitHub:
xcat --check-update # report whether a newer version exists (makes no changes)
xcat --update # download the latest xcat and replace this file in place--update preserves the executable bit and does an atomic replace. If the
installed file lives in a root-owned location (e.g. /usr/local/bin), it
re-runs the final move with sudo, prompting for your password.
In addition, a passive check runs automatically at most once every 24 hours, but only on an interactive terminal, and only ever prints a one-line notice when a newer version is available:
xcat: a newer version (1.1.0) is available — run 'xcat --update' (current: 1.0.0).
It never blocks, never runs in scripts/pipes (stderr must be a TTY), and fails silently when offline. Disable it entirely with:
export XCAT_NO_UPDATE_CHECK=1Detection is by the VERSION string, so the passive notice only fires on
tagged releases. Point updates at a fork or mirror with XCAT_UPDATE_URL.
The test suite is hermetic — it stubs a fake clipboard backend on PATH, so it
needs no display or real clipboard:
./tests/run.shStatic analysis:
shellcheck -S warning xcat tests/run.shBoth run automatically in CI (see .github/workflows/ci.yml).
MIT License
© 2025 Blaine Bouvier (@WebWalker3D)
See LICENSE for full text.