# snip - Minimal POSIX Snippet Manager A simple, POSIX-compatible snippet manager that follows the Unix philosophy. Store, search, and quickly access code snippets with cross-platform clipboard support. ## Features - **POSIX Compatible**: Works on any Unix-like system - **Git Integration**: Snippets directory is git-tracked for version control - **Cross-Platform**: Supports macOS and Linux clipboard operations - **Unix Philosophy**: Pipes in/out, does one thing well - **Minimal**: Single script, no dependencies beyond standard Unix tools ## Installation 1. Clone or download this repository 2. Run the setup script: ```bash ./setup ``` This will: - Create `~/.snippets` directory - Initialize git repository - Set up proper `.gitignore` - Add example snippets ## Usage ### Basic Commands ```bash # List all snippets ./snip list # Search snippets ./snip search "hello world" # Interactive selection (copies to clipboard) ./snip select # Add new snippet ./snip add bash hello 'echo "Hello, World!"' # Initialize snippets directory ./snip init ``` ### Directory Structure Snippets are organized in `~/.snippets/`: ``` ~/.snippets/ ├── .git/ ├── .gitignore ├── bash/ │ ├── hello-world.txt │ └── loop-example.txt ├── python/ │ └── fibonacci.txt └── git/ └── commit-message.txt ``` ### Adding Snippets ```bash # Add to existing category ./snip add bash "loop-example" 'for i in {1..10}; do echo $i; done' # Create new category ./snip add python "fibonacci" 'def fib(n): return n if n <= 1 else fib(n-1) + fib(n-2)' ``` ### Searching and Selecting ```bash # Search all snippets with content preview ./snip search "fibonacci" # Search only in specific category ./snip search "bash:hello" ./snip search "python:fibonacci" # Interactive selection with search ./snip select "bash" # Interactive selection of all snippets ./snip select ``` The search command now shows: - Content matches with relevant line previews and context - Category-specific search using `category:search-terms` syntax - Direct select commands for each result (e.g., `./snip select html:boilerplate`) ### Direct Selection You can directly select snippets using the `category:file` pattern: ```bash # Direct selection without interactive menu ./snip select "html:boilerplate" ./snip select "bash:hello-world" ``` ## Clipboard Support - **macOS**: Uses `pbcopy` - **Linux**: Uses `xclip` or `xsel` (whichever is available) ## Git Integration The snippets directory is a git repository, allowing you to: - Track changes to snippets - Sync across machines - Collaborate with others - Maintain version history ## Design Principles - **Single Responsibility**: One script, one purpose - **Composability**: Pipes in/out with other Unix tools - **Simplicity**: Minimal code, maximum functionality - **Portability**: POSIX shell, no external dependencies - **Immutability**: Snippets are files, not database entries ## Examples ```bash # Quick workflow ./snip search "commit" | head -5 ./snip select "git" # Pipe snippets to other tools ./snip list | grep "python" | xargs cat # Add snippet from file ./snip add bash "my-script" "$(cat my-script.sh)" ``` ## Requirements - POSIX-compatible shell (`/bin/sh`) - `find`, `grep`, `sort` (standard Unix tools) - `git` (for version control) - Clipboard utility: `pbcopy` (macOS) or `xclip`/`xsel` (Linux)