12 releases (4 breaking)
new 0.5.2 | Jan 16, 2025 |
---|---|
0.5.1 | Jan 12, 2025 |
0.4.1 | Jan 11, 2025 |
0.3.3 | Jan 9, 2025 |
0.1.2 | Jan 7, 2025 |
#765 in Command line utilities
1,093 downloads per month
58KB
1K
SLoC
rsnip: Smart Snippet Management with Template Support 🚀
A powerful command-line snippet manager that helps organize, find, and reuse text snippets with advanced templating capabilities. It features fuzzy search, intelligent shell integration, and dynamic template rendering.
Fast, Reliable, Yours: Why Snippets Outshine LLMs for boring Tasks
🌟 Key Features
- Smart Organization: Categorize snippets into types (shell commands, code, notes, etc.)
- Fuzzy Search: Lightning-fast fuzzy finding with interactive fzf-style interface
- Deep Shell Integration:
- Tab completion for snippets in bash
- Customizable aliases per snippet type
- Interactive fuzzy completion
- Dynamic Templates:
- Jinja2-style template syntax
- Date manipulation filters
- Environment variable access
- Safe shell command execution
- Flexible Configuration:
- TOML-based configuration
- Per-snippet-type settings
- Developer-Friendly: Comprehensive debugging support
🚀 Quick Start
Installation
cargo install rsnip
Basic Setup
- Initialize configuration:
# Generate default config
rsnip --generate-config > ~/.config/rsnip/config.toml
- Add shell integration to your
.bashrc
:
# Enable tab completion and aliases
source <(rsnip --generate bash)
- Create your first snippet file:
rsnip edit --ctype shell
Configuration
RSnip uses TOML configuration with rich customization options:
[snippet_types.shell]
source_file = "~/.config/rsnip/shell_snippets.txt"
description = "Shell commands and scripts"
alias = "," # Quick access alias
[snippet_types.git]
source_file = "~/.config/rsnip/git_snippets.txt"
description = "Git workflows"
alias = ",g" # Git-specific alias
[snippet_types.docker]
source_file = "~/.config/rsnip/docker_snippets.txt"
description = "Docker commands"
alias = ",d" # Docker-specific alias
Configuration is searched in:
~/.config/rsnip/config.toml
~/.config/rsnip/config.toml
/etc/rsnip/config.toml
Snippet Format
Snippets use a clear, readable format:
: Optional file-level comments
--- snippet_name
: Comment describing the snippet
: Additional comment lines
Content goes here
Multiple lines supported
---
--- template_example
: Example using templates
Hello {{ env_USER }}!
Created on: {{ current_date|strftime('%Y-%m-%d') }}
---
🛠️ Advanced Features
Shell Integration & Aliases
RSnip provides powerful shell integration:
- Type-Specific Aliases: Configure quick access aliases per snippet type:
[snippet_types.shell]
alias = "," # Use as: , mysnippet
For every alias an associated "edit" alias will be generated (prefix e): e,
.
- Smart Tab Completion:
- Works with both full commands and aliases
- Supports fuzzy matching
- Shows preview window with snippet content
Example usage:
# Using alias
, back<tab> # Fuzzy finds 'backup' snippet and copies to clipboard
e, back<tab> # Fuzzy finds 'backup' snippet and edits it
# Using full command
rsnip copy --ctype shell --input back<tab>
rsnip edit --ctype shell --input back<tab>
- Interactive Selection:
- FZF-style interface
- Live preview
- Fuzzy search
- Vim-style navigation
Template System
RSnip implements a powerful template engine with:
- Built-in Filters:
# Date formatting
{{ current_date|strftime('%Y-%m-%d') }}
# Date arithmetic
{{ current_date|add_days(7) }}
{{ current_date|subtract_days(7) }}
# Safe shell execution
{{ 'git rev-parse --short HEAD'|shell }}
- Environment Variables:
{{ env_HOME }} # Access $HOME
{{ env_USER }} # Access $USER
{{ env_PATH }} # Access $PATH
- Dynamic Content:
--- git-commit
: Create a dated commit
git commit -m "Update: {{ current_date|strftime('%Y-%m-%d') }} - {{ 'git status -s|wc -l'|shell }} files"
---
Command Reference
A universal command-line snippet manager
Usage: rsnip [OPTIONS] [COMMAND]
Commands:
types List available snippet types
list List all snippets
edit Edit snippet in system editor
complete Find completions with optional interactive selection
copy Copy text to clipboard
Options:
-d, --debug... Enable debug logging. Multiple flags (-d, -dd, -ddd) increase verbosity
--generate <GENERATOR> Generate shell completion scripts [possible values: bash, elvish, fish, powershell, zsh]
--generate-config Print default configuration to stdout
--info Display version and configuration information
-h, --help Print help
-V, --version Print version
Debug Support
Multiple verbosity levels for troubleshooting:
rsnip -d # Info level
rsnip -dd # Debug level
rsnip -ddd # Trace level
View system information:
rsnip --info
🔍 Usage Examples
Managing Shell Commands
- Create shell snippets:
--- aws-profile
: Switch AWS profile
export AWS_PROFILE={{ env_AWS_PROFILE|default('default') }}
---
--- docker-clean
: Remove unused Docker resources
docker system prune -af
---
- Use with aliases:
, aws<tab> # Fuzzy finds aws-profile
,d clean<tab> # Finds docker-clean using docker alias
Git Workflows
- Create git snippets:
--- commit-wip
: Create WIP commit with date
git commit -m "WIP: {{ current_date|strftime('%Y-%m-%d %H:%M') }}"
---
- Use with dedicated alias:
,g wip<tab> # Finds and applies commit-wip
🤝 Contributing
Contributions welcome! Please check our Contributing Guide.
Development Setup
# Clone repository
git clone https://github.com/yourusername/rsnip
cd rsnip
# Run tests
cargo test
# Build release
cargo build --release
📄 License
BSD 3-Clause License - see LICENSE for details.
🙏 Acknowledgments
Built with excellent Rust crates:
- clap: Command line parsing
- minijinja: Template engine
- skim: Fuzzy finder
- anyhow/thiserror: Error handling
- crossterm: Terminal UI
Similar Work
GitHub - knqyf263/pet: Simple command-line snippet manager
Shell integration inspired by: GitHub - ajeetdsouza/zoxide: A smarter cd command. Supports all major shells.
Dependencies
~20–35MB
~574K SLoC