|
1 | 1 | # snip — CLI Snippet Manager |
2 | 2 |
|
3 | | -A lightweight, cross-platform CLI for saving, searching, sharing, and running reusable code and shell snippets. |
| 3 | +<p align="center"> |
| 4 | + <a href="https://www.npmjs.com/package/snip-manager"> |
| 5 | + <img src="https://img.shields.io/npm/v/snip-manager.svg" alt="npm version"> |
| 6 | + </a> |
| 7 | + <a href="https://www.npmjs.com/package/snip-manager"> |
| 8 | + <img src="https://img.shields.io/npm/dt/snip-manager.svg" alt="npm downloads"> |
| 9 | + </a> |
| 10 | + <a href="https://github.com/bharath/snip/blob/main/LICENSE"> |
| 11 | + <img src="https://img.shields.io/npm/l/snip-manager.svg" alt="MIT License"> |
| 12 | + </a> |
| 13 | + <a href="https://github.com/bharath/snip/actions"> |
| 14 | + <img src="https://img.shields.io/github/actions/workflow/status/bharath/snip/node.js.yml" alt="Build Status"> |
| 15 | + </a> |
| 16 | +</p> |
| 17 | + |
| 18 | +> A lightweight, cross-platform CLI for saving, searching, sharing, and running reusable code and shell snippets. Built for developers who live in the terminal. |
| 19 | +
|
| 20 | +## Why snip? |
| 21 | + |
| 22 | +Stop hunting through your shell history for that one command. **snip** is your terminal's memory — save, search, and execute code snippets in milliseconds. |
| 23 | + |
| 24 | +- ⚡ **Lightning Fast** — Add, search, and run snippets in milliseconds |
| 25 | +- 🔍 **Fuzzy Search** — Find anything instantly across names, tags, and content |
| 26 | +- 🛡️ **Safety First** — Preview commands before execution, auto-detect dangerous operations |
| 27 | +- 🎨 **Interactive TUI** — Keyboard-first terminal UI with split-pane interface |
| 28 | +- 💾 **Flexible Storage** — JSON for simplicity, SQLite for scale |
| 29 | +- 🔄 **Gist Sync** — Backup and share via GitHub Gists |
| 30 | + |
| 31 | +## Quick Start |
4 | 32 |
|
5 | | -Built as an opinionated MVP with a TUI for efficient snippet management, optional SQLite persistence, and GitHub Gist sync. |
| 33 | +```bash |
| 34 | +# Install globally |
| 35 | +npm install -g snip-manager |
| 36 | + |
| 37 | +# Add a snippet from stdin |
| 38 | +echo 'docker run --rm -it -v "$PWD":/work -w /work ubuntu:24.04 bash' | snip add docker-run --lang sh --tags docker,run |
6 | 39 |
|
7 | | -Highlights |
8 | | -- **Fast Workflow**: add/list/search/run directly from your shell |
9 | | -- **Interactive TUI**: Fuzzy search and keyboard-first navigation (`snip ui`) |
10 | | -- **Persistence Options**: Choose between JSON or SQLite (with WASM fallback) |
11 | | -- **Gist Sync**: Share and backup your snippets via GitHub Gists |
12 | | -- **Safety**: Automated detection of dangerous commands (e.g., `rm -rf`) |
| 40 | +# Or add from your editor (opens $EDITOR) |
| 41 | +snip add my-script --lang bash --tags deploy,production |
| 42 | + |
| 43 | +# Search snippets |
| 44 | +snip search docker |
| 45 | + |
| 46 | +# Run a snippet |
| 47 | +snip run docker-run |
| 48 | + |
| 49 | +# Launch interactive TUI |
| 50 | +snip ui |
| 51 | +``` |
13 | 52 |
|
14 | 53 | ## Installation |
15 | 54 |
|
16 | | -Install globally via npm: |
| 55 | +### Prerequisites |
| 56 | + |
| 57 | +- Node.js 18+ |
| 58 | +- npm or yarn |
| 59 | + |
| 60 | +### Install via npm |
17 | 61 |
|
18 | 62 | ```bash |
19 | 63 | npm install -g snip-manager |
20 | 64 | ``` |
21 | 65 |
|
22 | | -## Quick start |
| 66 | +### Install via yarn |
23 | 67 |
|
24 | | -1. **Configure your editor** (optional, defaults to `$EDITOR` or `vi`): |
25 | | - ```bash |
26 | | - snip config set editor "vim" |
27 | | - ``` |
28 | | - |
29 | | -2. **Add a snippet** from stdin: |
30 | | - ```bash |
31 | | - echo 'docker run --rm -it -v "$PWD":/work -w /work ubuntu:24.04 bash' | snip add docker-run --lang sh --tags docker,run |
32 | | - ``` |
| 68 | +```bash |
| 69 | +yarn global add snip-manager |
| 70 | +``` |
33 | 71 |
|
34 | | -3. **List snippets**: |
35 | | - ```bash |
36 | | - snip list |
37 | | - ``` |
| 72 | +### Verify Installation |
38 | 73 |
|
39 | | -4. **Interactive TUI**: |
40 | | - ```bash |
41 | | - snip ui |
42 | | - ``` |
| 74 | +```bash |
| 75 | +snip --version |
| 76 | +``` |
43 | 77 |
|
44 | 78 | ## Commands |
| 79 | + |
45 | 80 | | Command | Description | |
46 | 81 | |---------|-------------| |
47 | | -| `snip add <name>` | Save a new snippet | |
48 | | -| `snip ui` | Enter the interactive TUI | |
| 82 | +| `snip add <name> --lang <lang> --tags <tag1,tag2>` | Save a new snippet from stdin or editor | |
| 83 | +| `snip ui` | Launch interactive TUI with fuzzy search | |
49 | 84 | | `snip list` | List all saved snippets | |
50 | | -| `snip search <q>` | Fuzzy search snippets | |
51 | | -| `snip run <id\|name>` | Execute a snippet | |
| 85 | +| `snip search <query>` | Fuzzy search across all snippets | |
| 86 | +| `snip run <id\|name>` | Execute a snippet safely | |
52 | 87 | | `snip edit <id\|name>` | Edit snippet content inline | |
53 | | -| `snip sync push <q>` | Upload to GitHub Gist | |
54 | | -| `snip sync pull <id>` | Download from GitHub Gist | |
55 | | -| `snip config` | View or change configuration | |
| 88 | +| `snip delete <id\|name>` | Remove a snippet | |
| 89 | +| `snip sync push [query]` | Upload matching snippets to GitHub Gist | |
| 90 | +| `snip sync pull <gist-id>` | Download snippets from GitHub Gist | |
| 91 | +| `snip config` | View or modify configuration | |
| 92 | +| `snip --version` | Show version information | |
| 93 | +| `snip --help` | Display help information | |
56 | 94 |
|
57 | | -## Features |
| 95 | +## Configuration |
| 96 | + |
| 97 | +### Set Your Editor |
| 98 | + |
| 99 | +```bash |
| 100 | +snip config set editor "vim" |
| 101 | +``` |
| 102 | + |
| 103 | +Supported editors: `vim`, `nvim`, `nano`, `code`, `subl` |
58 | 104 |
|
59 | | -### TUI Experience |
60 | | -The `snip ui` command provides a rich, split-pane interface inspired by modern terminal aesthetics. Use `j`/`k` to navigate, `e` to edit content, `a` to add new snippets, and `r` to run. |
| 105 | +### Enable SQLite Backend |
| 106 | + |
| 107 | +For larger snippet libraries (100+ snippets): |
61 | 108 |
|
62 | | -### SQLite Backend |
63 | | -For larger snippet libraries, enable SQLite: |
64 | 109 | ```bash |
65 | 110 | snip config set useSqlite true |
66 | 111 | ``` |
| 112 | + |
67 | 113 | Requires `better-sqlite3` for native performance, or falls back to `sql.js` (WebAssembly). |
68 | 114 |
|
| 115 | +### Configuration Options |
| 116 | + |
| 117 | +| Option | Default | Description | |
| 118 | +|--------|---------|-------------| |
| 119 | +| `editor` | `$EDITOR` or `vi` | Default editor for snippet creation | |
| 120 | +| `useSqlite` | `false` | Use SQLite instead of JSON storage | |
| 121 | +| `snippetDir` | `~/.snip` | Custom snippets directory | |
| 122 | + |
| 123 | +## Features |
| 124 | + |
| 125 | +### Interactive TUI |
| 126 | + |
| 127 | +Launch `snip ui` for a rich, split-pane interface: |
| 128 | + |
| 129 | +- **Navigation**: `j`/`k` or arrow keys to move up/down |
| 130 | +- **Search**: Type to fuzzy filter in real-time |
| 131 | +- **Add**: Press `a` to create a new snippet |
| 132 | +- **Edit**: Press `e` to edit selected snippet |
| 133 | +- **Run**: Press `r` to execute (shows preview first) |
| 134 | +- **Quit**: `q` or `Ctrl+C` |
| 135 | + |
| 136 | +### Safety Features |
| 137 | + |
| 138 | +snip automatically detects potentially dangerous commands: |
| 139 | + |
| 140 | +- `rm -rf` and similar recursive deletions |
| 141 | +- `sudo` commands |
| 142 | +- Network-intensive operations |
| 143 | +- Commands that could modify system state |
| 144 | + |
| 145 | +Preview is shown before execution — you confirm before running. |
| 146 | + |
| 147 | +### GitHub Gist Sync |
| 148 | + |
| 149 | +Backup and share your snippet library: |
| 150 | + |
| 151 | +```bash |
| 152 | +# Push all snippets to a new Gist |
| 153 | +snip sync push |
| 154 | + |
| 155 | +# Push matching snippets |
| 156 | +snip sync push docker |
| 157 | + |
| 158 | +# Pull from existing Gist |
| 159 | +snip sync pull <gist-id> |
| 160 | +``` |
| 161 | + |
| 162 | +## Troubleshooting |
| 163 | + |
| 164 | +### "command not found: snip" |
| 165 | + |
| 166 | +Ensure npm global bin directory is in your PATH: |
| 167 | + |
| 168 | +```bash |
| 169 | +# Add to ~/.zshrc or ~/.bashrc |
| 170 | +export PATH="$(npm global bin):$PATH" |
| 171 | +``` |
| 172 | + |
| 173 | +### Editor Not Opening |
| 174 | + |
| 175 | +Set your preferred editor: |
| 176 | + |
| 177 | +```bash |
| 178 | +snip config set editor "vim" |
| 179 | +``` |
| 180 | + |
| 181 | +### Permission Errors |
| 182 | + |
| 183 | +Fix npm permissions: |
| 184 | + |
| 185 | +```bash |
| 186 | +# Option 1: Use nvm |
| 187 | +nvm install --lts |
| 188 | +npm install -g snip-manager |
| 189 | + |
| 190 | +# Option 2: Use sudo (not recommended) |
| 191 | +sudo npm install -g snip-manager |
| 192 | +``` |
| 193 | + |
| 194 | +## Frequently Asked Questions |
| 195 | + |
| 196 | +### What is snip? |
| 197 | + |
| 198 | +snip is a CLI tool that helps developers manage and reuse code snippets directly from the terminal. Think of it as a personal library for your most-used commands and code blocks. |
| 199 | + |
| 200 | +### How is snip different from dotfiles? |
| 201 | + |
| 202 | +dotfiles store configuration files, while snip focuses specifically on **executable snippets** — commands and code blocks you run repeatedly. snip provides instant search and one-command execution. |
| 203 | + |
| 204 | +### Does snip support custom languages? |
| 205 | + |
| 206 | +Yes! Use `--lang` to specify the language: |
| 207 | + |
| 208 | +```bash |
| 209 | +snip add deploy --lang python --tags deploy |
| 210 | +``` |
| 211 | + |
| 212 | +### Can I import/export snippets? |
| 213 | + |
| 214 | +Yes, via GitHub Gist sync: |
| 215 | + |
| 216 | +```bash |
| 217 | +# Export to Gist |
| 218 | +snip sync push |
| 219 | + |
| 220 | +# Import from Gist |
| 221 | +snip sync pull <gist-id> |
| 222 | +``` |
| 223 | + |
| 224 | +### Is my data secure? |
| 225 | + |
| 226 | +Local snippets are stored in `~/.snip/` by default. Gist sync requires GitHub authentication. All data stays on your machine unless you explicitly choose to sync. |
| 227 | + |
69 | 228 | ## Contributing |
70 | | -Contributions are welcome! Please open an issue or submit a pull request. |
| 229 | + |
| 230 | +Contributions are welcome! Please read our [Contributing Guide](CONTRIBUTING.md) first. |
| 231 | + |
| 232 | +1. Fork the repository |
| 233 | +2. Create your feature branch (`git checkout -b feature/amazing-feature`) |
| 234 | +3. Commit your changes (`git commit -m 'Add amazing feature'`) |
| 235 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 236 | +5. Open a Pull Request |
| 237 | + |
| 238 | +## Security |
| 239 | + |
| 240 | +See [SECURITY.md](SECURITY.md) for our security policy and reporting guidelines. |
71 | 241 |
|
72 | 242 | ## License |
73 | | -MIT © 2026 Bharath. See the [LICENSE](./LICENSE) file for details. |
74 | 243 |
|
| 244 | +MIT License — see the [LICENSE](LICENSE) file for details. |
| 245 | + |
| 246 | +--- |
| 247 | + |
| 248 | +<p align="center"> |
| 249 | + Built for developers who live in the terminal. ⚡ |
| 250 | +</p> |
0 commit comments