rat is a powerful, feature-rich command-line utility that goes beyond simple file viewing. It combines streaming simplicity with modern enhancements including SSH support, archive viewing, structured data rendering, Git annotations, and inline image display.
-
TTY-aware dual mode - raw byte-perfect output when piped, rich mode when attached to a terminal
-
SSH Support - view files on remote servers seamlessly
-
Extended Language Support - 15+ programming languages with custom configuration support
-
Archive Viewing - .gz, .bz2, .tar, .zip and more
-
Structured Data Viewers - JSON tree visualization, CSV tables
-
Git Annotations - inline git blame with author and date information
-
Inline Image Display - supports Kitty, iTerm2, w3m, and Sixel protocols
-
Plugin Architecture - JSON-RPC based plugin system for custom renderers
-
Type Safe - built with Crystal for compile-time type safety
-
Input/Output Sanitization - safe handling of binary and malformed data
-
Paging Control -
--paging=auto|always|neverfor external pager integration -
Line-range & Limit Options -
--lines=START-END,--max-lines=N -
Clean Codebase in Crystal v1.18.2 - fast binary, easy to build & distribute
-
Input/Output Sanitization - safe handling of binary and malformed data
-
Paging Control -
--paging=auto|always|neverfor external pager integration -
Line-range & Limit Options -
--lines=START-END,--max-lines=N -
Clean Codebase in Crystal v1.18.2 - fast binary, easy to build & distribute
# Clone and build
git clone https://github.com/OkaVatti/rat.git
cd rat
shards install
crystal build main.cr -o rat --release# Basic file viewing with syntax highlighting
./rat file.cr
# SSH file viewing
./rat -S -L [email protected]:22 -K ~/.ssh/id_rsa -l "/home/user/code.rs"
# View with line numbers
./rat -n main.cr
# Git blame annotations
./rat -g lib/rat/cli.cr
# View JSON as tree
./rat data.json
# View CSV as table
./rat data.csv
# View compressed file
./rat archive.tar.gz
# View image (if terminal supports it)
./rat image.png
# Line range with numbers
./rat --lines=10-50 -n README.md
# Use custom language config
./rat -c ~/.config/rat/my-languages.json code.custom| Flag | Description |
|---|---|
--plain |
Disable all decorations (raw output) |
--fast |
Reduce highlighting overhead |
--paging=... |
Control pager behavior (auto, always, never) |
--lines=START-END |
Show only the specified inclusive line range |
--max-lines=N |
Stop after N lines (safety cap) |
-n, --number |
Show line numbers |
-S, --ssh |
Enable SSH mode |
-L, --location |
SSH location (user@host:port) |
-K, --key |
Path to SSH private key |
-P, --password |
SSH password |
-l, --remote-file |
Remote file path |
-g, --git-annotate |
Show git blame annotations |
-c, --config |
Custom language config file |
--list-plugins |
List available plugins |
View files on remote servers without manually SSHing:
# Using SSH key
rat -S -L [email protected]:22 -K ~/.ssh/lilith-devbox -l "~/code/lsd/lsd.cr"
# Using password (prompts if not provided)
rat -S -L [email protected]:22 -l "/var/log/app.log"
# Multiple files
rat -S -L user@server:22 -K ~/.ssh/key file1.cr file2.rsSupports 15+ languages out of the box:
- Crystal, Ruby, Rust, Python
- JavaScript, TypeScript, Go, C, C++, Java
- Shell (bash/zsh), YAML, JSON, Markdown
- HTML, CSS, SQL
Create ~/.config/rat/languages.json:
{
"languages": [
{
"name": "mylang",
"extensions": [".ml"],
"shebangs": ["mylang"],
"keywords": ["func", "var", "if", "else"],
"comment_single": "//",
"string_delimiters": ["\""],
"number_pattern": "\\b\\d+\\b"
}
]
}Then use:
rat -c ~/.config/rat/languages.json myfile.mlAutomatically detects and handles compressed files:
# Gzip
rat file.gz
# Bzip2
rat archive.bz2
# Tar (shows contents)
rat package.tar
# Zip (shows contents)
rat bundle.zipSupported formats: .gz, .bz2, .tar, .zip, .tgz, .tbz2, .xz, .lz
rat data.jsonOutput:
ββ name: "John Doe"
ββ age: 30
ββ address:
ββ street: "123 Main St"
ββ city: "Springfield"
rat data.csvOutput:
Name β Age β City
βββββββββββββββΌββββββΌββββββββββββββ
John Doe β 30 β Springfield
Jane Smith β 25 β Boston
View files with git blame information:
rat -g -n main.crOutput:
a3f2c8d1 John Doe 2025-01-15 β 1 require "./lib/rat/cli"
a3f2c8d1 John Doe 2025-01-15 β 2
b7e4f9a2 Jane Smith 2025-01-20 β 3 Rat::CLI.run(ARGV)
Supports multiple terminal graphics protocols:
- Kitty Graphics Protocol (kitty terminal)
- iTerm2 Inline Images (iTerm2)
- w3m (terminals with w3m support)
- Sixel (terminals with sixel support)
rat screenshot.png
rat logo.jpg
rat diagram.svgSupported formats: .jpg, .jpeg, .png, .gif, .webp, .svg, .ico, .bmp
If your terminal doesn't support graphics, rat shows metadata instead.
Create custom renderers using JSON-RPC protocol.
~/.config/rat/plugins/
βββ my-renderer.json # Plugin config
βββ my-renderer # Executable
{
"name": "my-renderer",
"version": "1.0.0",
"executable": "my-renderer",
"file_types": [".custom"],
"description": "Custom file renderer"
}Must accept JSON-RPC requests on stdin:
{
"jsonrpc": "2.0",
"method": "render",
"params": {
"path": "/path/to/file.custom",
"content": "file contents..."
},
"id": 1
}And return:
{
"jsonrpc": "2.0",
"result": "rendered output",
"id": 1
}rat --list-plugins- Composable & Pipeline-Safe - default to raw output when piped
- Progressive Enhancement - streaming first, rich UI only when terminal-attached
- Type Safe - Crystal's compile-time type checking prevents runtime errors
- Secure by Default - input/output sanitization, path validation
- Extensible Architecture - plugins and custom language configs
- Zero Configuration - works out of the box with sensible defaults
rat/
βββ main.cr # Entry point
βββ shard.yml # Crystal dependencies
βββ config/
β βββ languages.json # Default language configs
βββ lib/
β βββ rat/
β β βββ cli.cr # CLI logic & argument parsing
β β βββ reader.cr # Safe file/stdin reading
β β βββ formatter.cr # Output formatting
β β βββ ssh_client.cr # SSH file fetching
β β βββ archive_reader.cr # Archive handling
β β βββ image_viewer.cr # Inline image display
β β βββ structured_viewer.cr # JSON/CSV rendering
β β βββ git_annotator.cr # Git blame integration
β β βββ plugin_manager.cr # Plugin system
β βββ internals/
β βββ highlighter.cr # Syntax highlighting engine
β βββ language_config.cr # Language configuration
βββ spec/
βββ spec_helper.cr
βββ spec_highlighter.cr- Path Sanitization - prevents directory traversal attacks
- Input Validation - all user input is validated and sanitized
- Output Sanitization - strips control characters from output
- File Size Limits - warnings for very large files
- SSH Key Verification - secure SSH authentication
- Type Safety - Crystal's type system prevents entire classes of bugs
- Development - syntax-highlighted code viewing with git context
- DevOps - view logs on remote servers without SSH session
- Data Analysis - quick CSV/JSON inspection
- Documentation - view markdown files with proper formatting
- Debugging - inspect compressed logs and archives
- System Administration - remote file inspection with annotations
- SSH support for remote files
- Extended language syntax support
- Type-safe implementation
- Input/output sanitization
- Git annotations support
- Archive/compression support
- Structured data viewers (JSON, CSV)
- Plugin architecture (JSON-RPC)
- Inline image preview support
-
--follow/-fmode for live-tail with highlighting - Multi-file diff view
- Syntax theme customization
- WASM plugin support
- Performance profiling mode
- Configurable key bindings
Contributions are welcome! Areas for improvement:
- Additional language syntax definitions
- New image display protocols
- Plugin examples
- Performance optimizations
- Documentation improvements
Please open issues for bugs or feature requests, and submit pull requests with tests.
This project is licensed under the MIT License. See the LICENSE file for details.
Built with:
- Crystal Language - Fast, type-safe language
- ssh2-cr - SSH2 protocol support
- crystal-compress - Compression support
Made with β€οΈ for developers who live in the terminal.
Author: Lily Parker [email protected]