Skip to content

A lightweight, cross-platform CLI for saving, searching, sharing, and running reusable code and shell snippets. Built for developers who live in the terminal.

License

Notifications You must be signed in to change notification settings

Bharath-code/snip

snip — CLI Snippet Manager

🌐 Website · 🚀 Product Demo · 📦 npm · 📖 Docs

npm version npm downloads MIT License Build Status

A lightweight, cross-platform CLI for saving, searching, sharing, and running reusable code and shell snippets. Built for developers who live in the terminal.

Why snip?

Stop hunting through your shell history for that one command. snip is your terminal's memory — save, search, and execute code snippets in milliseconds.

  • Lightning Fast — Add, search, and run snippets in milliseconds
  • 🔍 Fuzzy Search — Find anything instantly across names, tags, and content
  • 🛡️ Safety First — Preview commands before execution, auto-detect dangerous operations
  • 🎨 Interactive TUI — Keyboard-first terminal UI with syntax highlighting, line numbers, and split-pane
  • 💾 Flexible Storage — JSON for simplicity, SQLite for scale
  • 🔄 Gist Sync — Backup and share via GitHub Gists
  • 🔗 fzf Integration — Pipe snippets through fzf with live preview
  • 🚀 Zero-friction execsnip exec runs immediately, no confirmation modal
  • 🩺 Health checksnip doctor validates your setup in one command
  • 🏷️ Shell aliaseseval "$(snip alias)" turns every snippet into a command

Why snip over X?

Feature snip pet navi tldr dotfiles / aliases
Run snippets directly ✅ Any language ✅ Shell only ✅ Shell only ❌ Reference only ✅ Shell only
Multi-language (JS, Python, Ruby…)
Interactive TUI ✅ Split-pane ✅ Basic
Dangerous command detection ✅ Auto-detect
fzf integration ✅ Native ✅ Core Manual
SQLite backend ✅ Optional
Gist sync ✅ Push/pull Manual
Cross-platform ✅ Node.js Go binary Rust binary Multi Varies
Zero config ✅ Works out of box Needs cheats Heavy setup

TL;DR: Other tools are great for shell commands. snip is for developers who save code — deploy scripts, API calls, Docker commands, JS utilities — across any language, with safety rails and a real TUI.

Quick Start

# Install globally
npm install -g snip-manager

# Add a snippet from stdin
echo 'docker run --rm -it -v "$PWD":/work -w /work ubuntu:24.04 bash' | snip add docker-run --lang sh --tags docker,run

# Or add from your editor (opens $EDITOR)
snip add my-script --lang bash --tags deploy,production

# Search snippets
snip search docker

# Run a snippet
snip run docker-run

# Launch interactive TUI
snip ui

Installation

Prerequisites

  • Node.js 18+
  • npm or yarn

Install via npm

npm install -g snip-manager

Install via yarn

yarn global add snip-manager

Verify Installation

snip --version

Commands

Command Description
snip add <name> --lang <lang> --tags <tag1,tag2> Save a new snippet from stdin or editor
snip ui Launch interactive TUI with fuzzy search
snip list [--json] List all saved snippets (JSON for scripting)
snip search <query> [--json] Fuzzy search across all snippets
snip run <id|name> Execute a snippet safely (with template prompts)
snip exec <id|name> [--dry-run] [--force] Run immediately — no preview modal
snip show <id|name> [--json] [--raw] Show snippet content
snip edit <id|name> Edit snippet content in $EDITOR
snip update <id|name> --tags <t> --lang <l> Update snippet tags or language
snip cp <source> <dest> Duplicate a snippet
snip mv <source> <newName> Rename a snippet
snip cat <id|name> Print raw content to stdout (for piping)
snip delete <id|name> Remove a snippet (alias: snip rm)
snip recent [count] Show recently used snippets
snip fzf Search snippets via fzf with live preview
snip grab <url> Import a snippet from a URL or github:user/repo/path
snip alias [shell] Generate shell aliases for all snippets
snip doctor Health check — verify storage, editor, fzf, gist
snip stats Show snippet library statistics
snip widget [shell] Output Ctrl+G shell widget for zsh/bash/fish
snip sync push [query] Upload matching snippets to GitHub Gist
snip sync pull <gist-id> Download snippets from GitHub Gist
snip config View or modify configuration
snip --version Show version information
snip --help Display help information

Configuration

Set Your Editor

snip config set editor "vim"

Supported editors: vim, nvim, nano, code, subl

Enable SQLite Backend

For larger snippet libraries (100+ snippets):

snip config set useSqlite true

Requires better-sqlite3 for native performance, or falls back to sql.js (WebAssembly).

Configuration Options

Option Default Description
editor $EDITOR or vi Default editor for snippet creation
useSqlite false Use SQLite instead of JSON storage
snippetDir ~/.snip Custom snippets directory

Features

Interactive TUI

Launch snip ui for a rich, split-pane interface:

  • Navigation: j/k or arrow keys to move up/down
  • Search: / to search — list filters live as you type
  • Preview: Syntax highlighting and line numbers
  • Add: Press a to create a new snippet
  • Edit: Press e to edit selected snippet
  • Run: Press r to execute (shows preview first)
  • Delete: Press d — type snippet name to confirm, then z to undo within 5s
  • Sort: Press s to cycle sort mode (persists across sessions)
  • Quit: q or Ctrl+C

Zero-Friction Execution

Skip the preview modal when you know what you're running:

# Run immediately
snip exec deploy-api

# Dry run — just print the content
snip exec deploy-api --dry-run

# Skip dangerous-command warning
snip exec deploy-api --force

Shell Aliases

Turn every snippet into a native shell command:

# Generate aliases for bash/zsh
eval "$(snip alias)"

# Now every snippet is a command:
deploy-api           # → snip exec deploy-api
docker-cleanup       # → snip exec docker-cleanup

Health Check

snip doctor
  ✓ Storage: JSON (42 snippets)
  ✓ Editor: code --wait
  ✓ Shell: /bin/zsh
  ✓ fzf: installed
  ✗ Gist sync: not configured

Pipe-Friendly Output

# Raw content for piping
snip cat deploy | sh
snip show deploy --raw | clipboard

# JSON for scripting
snip show deploy --json | jq .tags
snip search docker --json | jq '.[].name'
snip list --json | jq length

Snippet Management

snip cp deploy deploy-staging   # Duplicate
snip mv old-name new-name       # Rename
snip recent                     # Last 5 used
snip recent 10                  # Last 10 used

Safety Features

snip automatically detects potentially dangerous commands:

  • rm -rf and similar recursive deletions
  • sudo commands
  • Network-intensive operations
  • Commands that could modify system state

Preview is shown before execution — you confirm before running.

Parameterized Snippets

Use {{variable}} and {{variable:default}} syntax for reusable templates:

# Save a parameterized snippet
echo 'docker run --rm -it -v "{{dir:$PWD}}":/work {{image:ubuntu:24.04}} {{cmd:bash}}' \
  | snip add docker-dev --lang sh --tags docker

# Run it — snip prompts for each variable
snip run docker-dev
#   dir [/Users/me/project]: _
#   image [ubuntu:24.04]: node:20
#   cmd [bash]: sh

Variables support environment variable defaults with {{name:$ENV_VAR}}.

Grab from URL

Import snippets directly from any URL:

# Grab from a raw URL
snip grab https://gist.githubusercontent.com/.../deploy.sh --tags deploy

# Shorthand for GitHub files
snip grab github:user/repo/scripts/backup.sh

Language is auto-detected from file extension and shebang.

Shell Widget (Ctrl+G)

Bind snip to a hotkey — search and paste snippets inline without leaving your prompt:

# Zsh — add to ~/.zshrc
eval "$(snip widget zsh)"

# Bash — add to ~/.bashrc
eval "$(snip widget bash)"

# Fish — add to ~/.config/fish/config.fish
snip widget fish | source

# Now press Ctrl+G anywhere to search and insert a snippet

GitHub Gist Sync

Backup and share your snippet library:

# Push all snippets to a new Gist
snip sync push

# Push matching snippets
snip sync push docker

# Pull from existing Gist
snip sync pull <gist-id>

Shell Completions

Tab completions ship with snip for bash, zsh, and fish:

# Bash — add to ~/.bashrc
eval "$(snip completion bash)"

# Zsh — add to ~/.zshrc
eval "$(snip completion zsh)"

# Fish — add to ~/.config/fish/config.fish
snip completion fish | source

fzf Integration

If you have fzf installed, use snip fzf for a searchable list with a live preview pane:

# Search and preview snippets
snip fzf

# Pipe selected snippet to clipboard
snip fzf | pbcopy

# Bind to a shell shortcut (add to ~/.zshrc)
bindkey -s '^S' 'snip fzf\n'

Troubleshooting

"command not found: snip"

Ensure npm global bin directory is in your PATH:

# Add to ~/.zshrc or ~/.bashrc
export PATH="$(npm global bin):$PATH"

Editor Not Opening

Set your preferred editor:

snip config set editor "vim"

Permission Errors

Fix npm permissions:

# Option 1: Use nvm
nvm install --lts
npm install -g snip-manager

# Option 2: Use sudo (not recommended)
sudo npm install -g snip-manager

Frequently Asked Questions

What is snip?

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.

How is snip different from dotfiles?

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.

Does snip support custom languages?

Yes! Use --lang to specify the language:

snip add deploy --lang python --tags deploy

Can I import/export snippets?

Yes, via GitHub Gist sync:

# Export to Gist
snip sync push

# Import from Gist
snip sync pull <gist-id>

Is my data secure?

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.

Contributing

Contributions are welcome! Please read our Contributing Guide first.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Security

See SECURITY.md for our security policy and reporting guidelines.

License

MIT License — see the LICENSE file for details.


Built for developers who live in the terminal. ⚡

About

A lightweight, cross-platform CLI for saving, searching, sharing, and running reusable code and shell snippets. Built for developers who live in the terminal.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •