Skip to content
WebWalker3DPublic

About

Xcat copy utility

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xcat

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.


✨ Features

  • 📋 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:END shorthand (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 --install using:
    • apt-get, dnf, yum, pacman, zypper, or brew
    • (opt-in only — xcat never runs sudo unless you ask it to)
  • 🧱 Directory mode:
    • Non-recursive
    • Concatenates all regular text files
    • Supports --types=ext1,ext2 filters
    • Prefixes each chunk with its full path
  • 🧠 Advanced options:
    • --preview — syntax-highlight preview (with bat or batcat)
    • --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

⚙️ Requirements

  • Bash ≥ 4.0
  • One of the following clipboard utilities:
    • Linux / BSD: xclip (X11) or wl-clipboard (Wayland)
    • macOS: pbcopy
    • WSL: clip.exe

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).


🧩 Installation

sudo curl -L https://raw.githubusercontent.com/WebWalker3D/Xcat/main/xcat \
  -o /usr/local/bin/xcat
sudo chmod +x /usr/local/bin/xcat

Verify it’s working:

xcat -h

You should see the usage help.


💡 Usage

Synopsis

xcat [OPTIONS] [FILE]
  • If FILE is omitted, xcat reads from stdin.

  • If FILE is 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

Options

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, not xcat file --verify. Line ranges apply only to a single file or stdin, not to directories or multiple files.


🧪 Examples

Copy a whole file

xcat ~/.bashrc

Copy several files at once

xcat main.c util.c util.h    # each section prefixed with its path

Copy specific line ranges

xcat -s 10 -e 30 app.log
xcat -L 15: app.log
xcat -L :50 app.log

Copy from stdin (e.g. pipeline)

grep ERROR app.log | xcat -L :50
kubectl get pods -A | xcat

Copy all text files in a directory

xcat /etc/apache2/sites-available/

Filter by extension:

xcat /etc --types=conf,service

Use preview and verify modes

xcat -p --verify app.log

Compress output before copying

xcat --compress large.txt

Override clipboard backend

xcat --backend=wl-copy myfile.txt

Tee output to both clipboard and stdout

xcat --tee script.sh | wc -l

List available backends

xcat --list-backends

🧠 Clipboard Detection & Auto-Install

On first run, xcat tries the following in order:

  1. xclip -selection clipboard
  2. wl-copy
  3. pbcopy
  4. clip.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.


🚪 Exit Codes

Code Meaning
0 Success
1 Runtime failure (e.g. file not found, no clipboard backend)
2 Invalid usage (bad options, non-numeric values, etc.)

🧩 Version & Integrity Info

Each successful copy displays:

  • SHA-1 checksum of the payload
  • Optional compression and range info
  • Active clipboard backend (in verbose mode)

💬 Notes & Tips

  • 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 + --types is handy for aggregating config files.
  • Combine with fzf or bat for interactive snippet sharing.
  • Designed to be portable, predictable, and copy-ready anywhere.

🔄 Staying up to date

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=1

Detection 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.


🧪 Testing & Development

The test suite is hermetic — it stubs a fake clipboard backend on PATH, so it needs no display or real clipboard:

./tests/run.sh

Static analysis:

shellcheck -S warning xcat tests/run.sh

Both run automatically in CI (see .github/workflows/ci.yml).


🧾 License

MIT License © 2025 Blaine Bouvier (@WebWalker3D) See LICENSE for full text.

About

Xcat copy utility

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages