A simple snippet manager for Nushell that helps you organize and run reusable commands with Git-based version control.
amasia-snip.mp4
- Organize snippets in multiple source files
- Run instantly — execute snippets immediately
- Quick access by name or index
- Smart clipboard integration
- Git history tracking with time-travel support
- Pipe-friendly — works with stdin/stdout
- Multiple sources for different contexts
- Interactive selection with fzf support
# One-line install
http get https://raw.githubusercontent.com/amasialabs/nushell-modules/main/install.nu | nu -c $in# For first-time installation, source the config
source "~/.amasia/nushell/config.nu"# Do not forget
use amasia/snip# Verify installation
snip ls
# Output: Shows the default hello-world snippet# Create a snippet
snip new hello "echo 'Hello, Nushell!'"
# Output: Added snippet 'hello' to source 'default'
# Run it
snip run hello
# Output: Hello, Nushell!
# List all snippets
snip ls
╭───┬─────────┬────────────────────────────┬─────────╮
│ # │ name │ commands │ source │
├───┼─────────┼────────────────────────────┼─────────┤
│ 0 │ hello │ ["echo 'Hello, Nushell!'"] │ default │
╰───┴─────────┴────────────────────────────┴─────────╯# Create snippets with multiple commands
snip new deploy --description "Deploy the application" [
"git pull"
"npm install"
"npm run build"
]
# Update existing snippet
snip update deploy ["git pull" "npm run deploy"]
# Also supports positional commands (single or multiple)
snip new quick-one "echo test"
snip update quick-one "echo updated"
snip new chain "echo a" "echo b"
snip new deploy2 ["git pull" "npm install" "npm run build"]
# Remove snippet(s)
snip rm deploy
snip rm hello docker-active
# Batch remove with pipe
["old-snippet1" "old-snippet2"] | snip rmNote: flags (e.g., --source, --description) can be placed before or after positional commands; both forms work:
snip new demo --source work "echo hi"
snip new demo "echo hi" --source work
snip update demo --source work "echo hi"
snip update demo "echo hi" --source work# Run by name
snip run deploy
# Run using shorthand -r flag
snip -r deploy
# Run by index (from snip ls output)
snip run 0
snip -r 0
# Show snippet details
snip show deploy
╭───────────────┬──────────────────────────────────────╮
│ Name │ deploy │
│ Description │ Deploy the application │
│ Command │ git pull │
│ │ npm install │
│ │ npm run build │
│ Source │ default │
╰───────────────┴──────────────────────────────────────╯
# Paste to command line
snip paste deploy # → command line buffer
snip paste deploy -c # → clipboard only
# Interactive selection with fzf (requires fzf installed)
snip pick # select from all snippets, return name
snip pick -c # select and copy to clipboard
snip pick -r # select and run immediately
snip pick --source work # select only from a specific source
snip | where source == "work" | snip pick # filter then selectSources let you organize snippets by context (work, personal, project-specific):
# Create a new source
snip source new work
# Add snippet to specific source
snip new ssh-prod --source work "ssh user@prod.example.com"
# List sources
snip source ls
snip source # sugar for `source ls`
snip source --from-hash <h> # sugar for `source ls --from-hash <h>`
╭───┬─────────╮
│ # │ source │
├───┼─────────┤
│ 0 │ default │
│ 1 │ work │
╰───┴─────────╯
# Remove source (cannot remove default)
snip source rm workAll commands work with pipes for powerful workflows:
# Create snippet from a docker command
"docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | grep -v Exited" | snip new docker-active
# Create from history
history | last 5 | get command | snip new recent-commands
# Run snippet from selection
snip | where source == "work" | get name | first | snip run
# Update snippet from command output
history | last 10 | get command | str join "\n" | snip update daily-workflow
# Interactive selection (with fzf)
snip ls | get name | str join (char nl) | fzf | snip run
# Batch operations
snip rm old-snippet1 old-snippet2 old-snippet3
["old-snippet1" "old-snippet2" "old-snippet3"] | snip rm
# Filter and process
snip ls | where name =~ "deploy" | each {|s| snip show $s.name }Every change is automatically tracked in Git:
# View history
snip history
╭───┬─────────┬───────────────────────────┬────────────────────────────╮
│ # │ hash │ date │ message │
├───┼─────────┼───────────────────────────┼────────────────────────────┤
│ 0 │ a3c4d5f │ 2025-09-24 15:30:00 +0400 │ Update snippet: deploy │
│ 1 │ b2e3f6g │ 2025-09-24 15:25:00 +0400 │ Add snippet: deploy in │
│ │ │ │ default │
│ 2 │ c1d2e3f │ 2025-09-24 15:20:00 +0400 │ Initial commit: existing │
│ │ │ │ snippets │
╰───┴─────────┴───────────────────────────┴────────────────────────────╯
# Limit history output
snip history --limit 10
# View snippets from a specific commit
snip ls --from-hash b2e3f6g
# Run a snippet as it was at a specific commit
snip run deploy --from-hash b2e3f6g
# Show snippet details from history
snip show deploy --from-hash c1d2e3f
# Paste a historical snippet
snip paste ssh-prod --from-hash a3c4d5f -c
# View sources at a specific commit
snip source ls --from-hash b2e3f6g
snip source --from-hash b2e3f6g # sugar
# Revert all snippets to a previous state
snip history revert a3c4d5f
# Output: Reverted snippets to commit a3c4d5f
# Revert with custom message
snip history revert a3c4d5f --message "Restore working deployment scripts"- Override data directory with
AMASIA_NU_DATA_DIR(default is~/.amasia/nushell/data). Useful for testing or portable setups.
$env.AMASIA_NU_DATA_DIR = "/tmp/amasia-nu"
use amasia/snip
snip ls| Command | Description | Example |
|---|---|---|
snip ls |
List all snippets | snip ls |
snip new |
Create new snippet | snip new test "echo test" |
snip update |
Update snippet | snip update test "echo updated" |
snip rm |
Remove snippet(s) | snip rm a b or ["a", "b"] | snip rm |
snip run |
Execute snippet | snip run test or snip -r test |
snip show |
Show snippet details | snip show test |
snip paste |
Paste to buffer/clipboard | snip paste test -c |
snip config |
Show configuration | snip config |
snip history |
Show Git history | snip history --limit 20 |
snip history revert |
Revert to commit | snip history revert a3c4d5f |
| Command | Description | Example |
|---|---|---|
snip source ls |
List sources | snip source ls |
snip source new |
Create source | snip source new personal |
snip source rm |
Remove source | snip source rm personal |
--run / -r- Shorthand for run subcommand (global flag, e.g.,snip -r deploy)--source <name>- Specify a source file (for new, update, run, show, paste)- Flags may appear before or after positional commands (Nushell parses flags anywhere), e.g.,
snip new demo --source work "echo hi"orsnip new demo "echo hi" --source work. --description <text>- Add description (for new, update)--clipboard / -c- Copy to clipboard (for paste, pick)--run / -r- Run snippet immediately (for pick subcommand)--limit <n>- Limit output rows (for history)--from-hash <hash>- Load snippets from a specific commit (for ls, show, run, paste, source ls)
# Save last command as snippet
history | last 1 | get command | snip new last-cmd# Create project source
snip source new myproject
# Add project commands
snip new test --source myproject "cargo test"
snip new build --source myproject "cargo build --release"# Complex deployment
snip new deploy-full [
"git stash"
"git pull origin main"
"git stash pop"
"docker-compose down"
"docker-compose build"
"docker-compose up -d"
"docker-compose logs -f"
]
# Secure SSH with password manager
snip new ssh-secure [
"pass -c 'servers/production/admin'" # Copy password to clipboard
"env LANG=en_US.UTF-8 ssh -o PreferredAuthentications=password admin@server.example.com"
"'' | pbcopy" # Clear clipboard after login
]# Run all test-related snippets
snip ls | where name =~ "test" | each { |it| snip run $it.name }
# Copy all work snippets to clipboard
snip ls | where source == "work" | each { |it| snip paste $it.name -c }All snippet data is stored in:
~/.amasia/nushell/data/snip/
├── .git/ # Git history
├── default.nuon # Default snippets
├── work.nuon # Work snippets (example)
└── *.nuon # Other source files
-
Module is not found after installation
# Ensure the module is in the right path ls ~/.amasia/nushell/modules/amasia/snip/ # Reload your config source $nu.config-path
-
Git history is not working
# Check if Git is installed which git # Reinitialize if needed cd ~/.amasia/nushell/data/snip git init
-
Clipboard paste is not working
- macOS: Ensure
pbcopyis available - Linux: Install
xcliporwl-clipboard - Windows: Uses built-in clipboard
- macOS: Ensure
-
Snippet with spaces in commands
# Use list syntax for complex commands snip new backup [ "tar -czf backup.tar.gz ." "mv backup.tar.gz ~/backups/" ]
Every change to your snippets is automatically committed to a local Git repository. This provides:
- Safety: Never lose a snippet accidentally
- History: See when and what changed
- Recovery: Restore deleted or modified snippets
- Collaboration: Share your snippets repo with your team
# View what changed recently
snip history --limit 5MIT