rgrc - Rusty Generic Colouriser
A fast, Rust-based command-line tool that colorizes the output of other commands using regex-based rules with advanced count/replace functionality, similar to the classic grc (Generic Colouriser) utility.
Latest Features: Full implementation of count/replace functionality with backreference support, advanced matching controls (once/more/stop), optimized performance with intelligent caching, real-time output buffering for interactive commands, and embedded configuration files for portable deployment.
Features
- π High Performance: Written in Rust with optimized regex-based colorization
- π¨ Rich Colorization: Supports ANSI colors, styles, and attributes with count/replace functionality
- π§ Flexible Configuration: Compatible with grc/grcat configuration files; supports embedded configurations for portable deployment
- π Shell Integration: Generates aliases for popular commands
- π Comprehensive: Supports 80+ pre-configured commands
- β‘ Advanced Matching: Regex-based rules with intelligent caching, pattern optimization, and advanced count/replace controls
- π Text Transformation: Replace matched text with backreference support for output modification
Quick Start
Installation
From Source
Using Cargo
Basic Usage
# Colorize ping output
# Colorize ls output
# Colorize any command
)
)
)
continue
Generate Shell Aliases
# Show aliases for supported commands
# Generate aliases for all known commands
# Add to your shell profile
Configuration
Configuration Files
rgrc reads configuration from multiple locations:
~/.rgrc # User-specific config
~/.config/rgrc/rgrc.conf # XDG config location
/usr/local/etc/rgrc.conf # System-wide config
/etc/rgrc.conf # Fallback system config
grcat Compatibility
rgrc is fully compatible with grc/grcat configuration files:
~/.config/rgrc/ # rgrc-specific configs
~/.local/share/rgrc/ # User share directory
/usr/local/share/rgrc/ # Local share directory
/usr/share/rgrc/ # System share directory
~/.config/grc/ # grc compatibility
~/.local/share/grc/ # grc compatibility
/usr/local/share/grc/ # grc compatibility
/usr/share/grc/ # grc compatibility
Supported Commands
rgrc comes with pre-configured colorization rules for 80+ commands:
System Monitoring: df, free, ps, top, vmstat, iostat
Network Tools: ping, traceroute, netstat, ss, ip, curl
Development: gcc, make, docker, kubectl, git
File Operations: ls, find, du, mount, fdisk
And many more...
Command Line Options
Usage: rgrc [OPTIONS] COMMAND [ARGS...]
Options:
--help Show help message
--aliases Generate shell aliases for supported commands
--all-aliases Generate aliases for all known commands
--except=CMD,... Exclude commands from alias generation
--color=on|off|auto Control color output (default: auto)
Examples
Basic Colorization
# Colorize ping output
# Colorize disk usage
# Colorize compilation output
# Colorize Docker commands
Advanced Usage
# Force color output
# Disable colors
# Real-time output for interactive commands
# Generate aliases for specific commands
|
# Exclude certain commands from aliases
# Configuration modes:
# Default (embedded + file system): Uses embedded configs first, falls back to file system
Shell Integration
# Bash
# Zsh
# Fish
Configuration Examples
Custom Command Configuration
Create ~/.config/rgrc/conf.mycommand:
regexp=^ERROR
colours=red,bold
regexp=^WARNING
colours=yellow
regexp=^INFO
colours=green
Advanced Matching Control
Use count and replace fields for sophisticated pattern matching:
# Match only once per line
regexp=^\s*#
colours=cyan
count=once
# Replace matched text
regexp=(ERROR|WARN|INFO)
colours=red,yellow,green
replace=\1:
# Stop processing after first match
regexp=^FATAL
colours=red,bold
count=stop
Count Options:
once: Match only the first occurrence per linemore: Match all occurrences (default)stop: Match first occurrence and stop processing the line
Replace Field:
- Supports backreferences (
\1,\2, etc.) - Empty string removes matched text
- Can transform output content
Extending Existing Commands
Add rules to ~/.rgrc:
# Custom rules for existing commands
regexp=^CUSTOM
colours=blue,underline
Performance
- Real-time Output: Line-buffered writer ensures immediate output for interactive commands like
ping,tail, andwatch - Zero-copy Operations: Efficient memory usage with minimal allocations and streaming I/O
- Regex Optimization: Uses fancy-regex with advanced pattern matching, backtracking control, and result caching
- ANSI Optimization: Merges adjacent styles using run-length encoding to reduce escape sequences
- Count/Replace Support: Advanced matching control with text substitution capabilities and line reprocessing
Development
Building from Source
# Clone repository
# Build debug version
# Build release version (with embedded configs - default)
# Build with embedded configurations (explicit)
# Build without embedded configurations (file system only)
### Embed mode when installing with cargo
)
)
)
)
)
If installing from a published crate on crates.io, whether embed-configs is
enabled by default depends on how that specific release was published. If you
need a portable, self-contained binary, explicitly pass --features embed-configs (by default).
Optional: build with timing instrumentation for diagnostics
---------------------------------------------------------
For troubleshooting we provide a small instrumentation feature that prints
per-stage timings to stderr when enabled. Build with the timetrace feature
and set the RGRCTIME environment variable when running to enable timings.
Build instrumented binary:
# cargo build -p rgrc --release --features timetrace
#```
)
Project Structure
rgrc/
βββ src/
β βββ main.rs # CLI entry point
β βββ lib.rs # Core library
β βββ args.rs # Command-line argument parsing
β βββ buffer.rs # Buffered writers for real-time output
β βββ colorizer.rs # Colorization engine
β βββ grc.rs # Configuration parsing
β βββ utils.rs # Utility functions
βββ tests/
β βββ lib_tests.rs # Library unit tests
β βββ colorizer_tests.rs # Colorizer functionality tests
β βββ grc_tests.rs # Configuration parsing tests
βββ doc/
β βββ rgrc.1.md # Manual page (markdown)
βββ share/ # Pre-configured rules
βββ etc/ # Shell completions
βββ target/ # Build artifacts
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Run tests:
cargo test(runs all 126+ tests) - Run specific test suites:
cargo test --lib- Core library testscargo test --test colorizer_tests- Colorizer testscargo test --test grc_tests- Configuration tests
- Submit a pull request
Compatibility
- Operating Systems: Linux, macOS, Windows (with WSL)
- Shells: Bash, Zsh, Fish, and others supporting ANSI escape sequences
- Terminals: Any ANSI-compatible terminal with 256-color support
- grc Compatibility: Drop-in replacement for grc with enhanced count/replace functionality and improved performance
- Configuration Files: Fully compatible with existing grc/grcat configuration files and directory structures
License
MIT License - see LICENSE file for details.
Credits
- Inspired by the original
grc(Generic Colouriser) by Radovan GarabΓk,grc-rsby Lars Christensen - Built with Rust and console