GitHub - brianredbeard/rucat: A `cat` like tool for displaying multiple files with fenced delimiters.
Extracto
A `cat` like tool for displaying multiple files with fenced delimiters. - brianredbeard/rucat
Resumen
Resumen Principal
rucat emerge como una herramienta fundamental y versátil para la era de los Large Language Models (LLMs), redefiniendo la utilidad del comando cat
tradicional. Desarrollada en Rust para garantizar rendimiento y seguridad, esta utilidad es presentada como un recurso indispensable para todo ingeniero de prompts y profesional que interactúa con código o archivos de texto en la terminal. Su principal valor reside en su capacidad para consolidar rápidamente el contexto de múltiples archivos en un único bloque de texto bien estructurado, optimizado para ser utilizado en prompts de IA. Esto resuelve el desafío de proporcionar información completa y precisa a asistentes de IA para tareas complejas como depuración, refactorización o análisis de repositorios, superando la lentitud y propensión a errores del copiado y pegado manual. rucat va más allá de la mera concatenación, ofreciendo múltiples formatos de salida, numeración de líneas, formato sensible a la sintaxis y soporte avanzado para el portapapeles, acelerando significativamente los flujos de trabajo de desarrollo impulsados por IA.
Elementos Clave
- Consolidación de Contexto para IA: rucat está diseñado específicamente para optimizar las interacciones con LLMs al agrupar eficientemente el contenido de múltiples archivos en un formato coherente. El ejemplo de recopilar el estado de un repositorio Git (
.git/{HEAD,config,info/exclude,logs/HEAD,logs/refs/heads/*}
) ilustra cómo puede generar instantáneamente un bloque de texto formateado en Markdown, listo para ser pegado directamente en un chat de IA, garantizando un contexto completo y sin ambigüedades. - Múltiples Formatos de Salida Flexibles: La herramienta ofrece una amplia gama de formatos para presentar el contenido, adaptándose a diversas necesidades. Esto incluye
ansi
(con bordes configurables),utf8
(con bordes de dibujo de caja),markdown
(bloques de código GitHub-flavored con detección automática de lenguaje),ascii
(encabezados simples),xml
(salida estructurada con metadatos) yjson
(ideal para scripting). También destaca el formatopretty
con resaltado de sintaxis basado en banderas, modelines de Vim o extensiones de archivo. - Soporte Avanzado para el Portapapeles: La integración con el sistema de portapapeles es una característica crítica para la productividad. Mediante la bandera
-c
o--copy
, rucat puede copiar su salida directamente, eliminando pasos intermedios. Soporta múltiples proveedores de portapapeles, incluyendo el nativo en Windows, macOS y Linux (X11/Wayland), así como secuencias de escape de terminal (OSC 52 para tmux/SSH, OSC 5522 para Kitty), con detección automática del proveedor más adecuado. - Capacidades de Entrada y Manipulación de Rutas: rucat es altamente flexible en la gestión de entradas, pudiendo procesar múltiples archivos y directorios, leer desde
stdin
para integrarse en pipelines de shell, y manejar listas de archivos terminadas en NUL (mediante-0
o--null
) de comandos comofind
. Además, la opción--strip N
permite limpiar los encabezados de archivo eliminando componentes de ruta líderes, útil para proyectos anidados o para una presentación más concisa.
Análisis e Implicaciones
rucat impacta directamente la eficiencia en el desarrollo al democratizar el acceso al contexto completo para herramientas de IA, lo que se traduce en respuestas más precisas y útiles de los modelos. Su capacidad para automatizar la recopilación y el formato de datos críticos reduce drásticamente el tiempo y el esfuerzo manual, permitiendo a desarrolladores y administradores centrarse en tareas de mayor valor añadido. Esta herramienta posiciona a los ingenieros de prompts en una ventaja competitiva, habilitando interacciones de IA más profundas y significativas.
Contexto Adicional
El proyecto, simbolizado por su mascota "Rucus", está diseñado para ser robusto y rápido gracias a su implementación en Rust. Además de su construcción desde el código fuente con Cargo, rucat ofrece la conveniencia de la instalación a través de Homebrew para usuarios de macOS y tiene soporte incorporado para la generación de paquetes .deb
para sistemas Debian/Ubuntu.
Contenido
rucat
- A versatile cat
clone
rucat
is cat
reborn for the era of LLMs. A critical tool for every prompt
engineer.
Written in Rust. It goes beyond simple file concatenation, offering multiple output formats, line numbering, syntax-aware formatting, and clipboard support, making it an ideal tool for developers, system administrators, and anyone working with code or text files in the terminal.
Powering AI and Development Workflows
In modern development, AI assistants are invaluable for complex tasks like debugging, refactoring, or repository analysis. However, their effectiveness hinges on the quality and completeness of the context you provide. Manually copying and pasting from numerous files is slow and error-prone.
rucat
excels at rapidly consolidating context from multiple files into a
single, well-structured block of text, perfect for an AI prompt.
If you're troubleshooting a complex git
history issue and need to provide an
AI with the full state of your repository's refs and logs, you can run:
# Quickly gather all relevant git state files into one block $ rucat .git/{HEAD,config,info/exclude,logs/HEAD,logs/refs/heads/*} # Or copy directly to clipboard for pasting into AI chat $ rucat --copy .git/{HEAD,config,info/exclude,logs/HEAD,logs/refs/heads/*}
```
---
File: .git/HEAD
---
```
ref: refs/heads/main
```
---
File: .git/config
---
```
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/poundifdef/SmoothMQ
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
```
---
File: .git/info/exclude
---
```
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
```
---
File: .git/logs/HEAD
---
```
0000000000000000000000000000000000000000 2770c4b21a3755e95652c24b71ac7cad87b532dc Brian 'redbeard' Harrington <redbeard@dead-city.org> 1718820643 -0700 clone: from https://github.com/poundifdef/SmoothMQ
```
---
File: .git/logs/refs/heads/main
---
```
0000000000000000000000000000000000000000 2770c4b21a3755e95652c24b71ac7cad87b532dc Brian 'redbeard' Harrington <redbeard@dead-city.org> 1718820643 -0700 clone: from https://github.com/poundifdef/SmoothMQ
```
This command instantly generates a clean, markdown-formatted output, with each file's content neatly separated and labeled:
The resulting text can be piped to your clipboard and pasted directly into your
AI chat, delivering complete and unambiguous context in seconds. This makes
rucat
an essential tool for accelerating AI-driven development.
Features
- Multiple Output Formats: Display content in various styles, including:
ansi
: Nicely formatted with borders (width-configurable via--ansi-width
).utf8
: Fancy UTF-8 box-drawing borders (width-configurable via--utf8-width
).markdown
: GitHub-flavored Markdown code blocks, with automatic language detection from the file extension.ascii
: Simple=== file.txt ===
headers for easy separation.xml
: Structured XML output with file and line metadata.json
: A clean JSON array of file entries, perfect for scripting and programmatic use.pretty
: Syntax highlighting for a wide range of languages. Syntax is chosen based on: 1) the--pretty-syntax
flag, 2) a Vim modeline in the file (e.g.,vim: ft=rust
), or 3) the file extension.
- Line Numbering: Prepend line numbers to every line with the
-n
or--numbers
flag. - Clipboard Support: Copy output directly to the system clipboard with the
-c
or--copy
flag. Supports multiple clipboard providers:- Native clipboard on Windows, macOS, and Linux (X11/Wayland)
- Terminal escape sequences (OSC 52 for tmux/SSH, OSC 5522 for Kitty)
- Automatic provider detection based on your environment
- Flexible Input:
- Process multiple files and directories.
- Read from
stdin
, allowing it to be used in shell pipelines. - Handle NUL-terminated file lists from commands like
find ... -print0
using the-0
or--null
flag.
- Path Manipulation: Use
--strip N
to remove leading path components from file headers, cleaning up output for nested projects. - Packaging:
- Built-in support for generating
.deb
packages for Debian/Ubuntu systems viacargo deb
.
- Built-in support for generating
- Robust and Fast: Built with Rust for performance and memory safety.
Installation
From Homebrew (for macOS users)
If you are on macOS and have Homebrew installed, you can install rucat
with a single command:
brew install brianredbeard/rucat/rucat
From source with Cargo
If you have the Rust toolchain installed, you can build and install rucat
directly from source. From the root of the project repository:
To build without clipboard support (reduces dependencies):
cargo install --path . --no-default-features
Building Packages
This project is configured to build .deb
packages using standard Cargo
tooling. First, ensure you have the necessary packaging subcommand installed:
Then, you can build the package from the project root:
# Build .deb package (output in target/debian/)
cargo deb
The binary will be placed in ~/.cargo/bin
.
Cross-compiling from macOS to Linux
When cross-compiling from macOS to Linux, rustc
needs a C-language toolchain
that can link executables for the Linux target. The native macOS toolchain
cannot do this. You can install the necessary toolchains using Homebrew, but it
requires adding a new formula tap first.
This is a one-time setup for your development machine. No changes are needed for the project's code.
-
Install Cross-Compilation Toolchains with Homebrew
First, tap the repository that contains the toolchains. Then, install them.
brew tap messense/macos-cross-toolchains brew install aarch64-unknown-linux-gnu brew install x86_64-unknown-linux-gnu
-
Configure Cargo to Use the New Linkers
You must tell Cargo to use these newly installed linkers for the respective targets. Create or edit the file
~/.cargo/config.toml
(this is Cargo's global configuration file in your home directory, not your project directory) and add the following content:[target.aarch64-unknown-linux-gnu] linker = "aarch64-unknown-linux-gnu-gcc" [target.x86_64-unknown-linux-gnu] linker = "x86_64-unknown-linux-gnu-gcc"
After completing these two steps, your system will be properly configured for
cross-compilation, and make cross-build-all
should succeed.
Usage
Basic Usage
# Display a single file rucat src/main.rs # Display multiple files rucat README.md Cargo.toml # Pipe content from another command ls -1 src/formatters | rucat # Copy output to clipboard rucat --copy src/main.rs
Formatting Options
rucat
defaults to the markdown
format. Use the -f
or --format
flag to
change it.
# Use the ANSI formatter with a width of 80 columns and line numbers rucat -f ansi --ansi-width 80 -n src/main.rs # Use the simple ASCII format rucat -f ascii src/main.rs # Get JSON output for scripting rucat -f json src/main.rs > output.json # Use the pretty-printer with syntax highlighting rucat -f pretty src/main.rs # Force a specific syntax for the pretty-printer rucat -f pretty --pretty-syntax sh < 'my-script-without-extension' # Pretty-print and copy to clipboard rucat -f pretty --copy src/main.rs
Advanced Input
rucat
can process a NUL-separated list of files from standard input, which is
safer and more robust than using xargs
. This is especially useful with find
.
# Find all Rust files and display them using the markdown format find src -name "*.rs" -print0 | rucat -0 -f markdown # Find and copy all configuration files to clipboard find . -name "*.toml" -print0 | rucat -0 --copy
Path Stripping
When working with deep directory structures, the full file path can be noisy.
Use --strip
to shorten the paths in the output headers.
# Before stripping: === src/formatters/ansi.rs === rucat -f ascii src/formatters/ansi.rs # After stripping 2 components: === ansi.rs === rucat -f ascii --strip 2 src/formatters/ansi.rs
Clipboard Support
The --copy
flag allows you to copy the output directly to your system clipboard
while still printing to stdout. This is particularly useful for quickly gathering
code context for AI assistants or sharing snippets with colleagues.
# Copy a single file to clipboard rucat --copy src/main.rs # Copy multiple files with pretty formatting rucat -f pretty --copy src/*.rs # Copy from stdin echo "Hello, World!" | rucat --copy # Works over SSH with OSC 52 support (tmux, modern terminals) ssh remote-server "rucat --copy /etc/nginx/nginx.conf"
The clipboard feature automatically detects the best provider for your environment:
- On desktop systems, it uses the native clipboard
- In SSH sessions or tmux, it uses OSC 52 escape sequences
- In Kitty terminal, it can use OSC 5522 for better compatibility
- Falls back gracefully if no clipboard is available
Configuration
rucat
can be configured with a TOML file to set your preferred default
options. Create a file at ~/.config/rucat/config.toml
(or the equivalent XDG
config path on your OS).
Command-line arguments will always override settings from this file.
Example config.toml
:
# Default output format. # Possible values: "ansi", "utf8", "markdown", "ascii", "xml", "json", # "pretty" format = "ansi" # Default to showing line numbers. numbers = true # Default number of path components to strip from filenames. strip = 1 # Default width for the "ansi" and "utf8" formatters. ansi_width = 120 utf8_width = 120 # Default syntax for the "pretty" formatter. pretty_syntax = "rust"
Contributing
Contributions are welcome! If you have a feature request, bug report, or pull request, please feel free to open an issue or submit a PR.
This tool was proudly co-written using Aider
License
This project is licensed under the GNU General Public License v3.0.
Fuente: GitHub