A CLI tool for developers to save and retrieve commonly used code snippets.
go install github.com/hayzedd2/snippet-cli/cmd/snippet@latest- Save code snippets from files via CLI
- Save entire files as snippets
- Copy snippets to the clipboard for quick use
- List all saved snippets with their tags and creation timestamps
- Retrieve specific snippets by their tags
- Delete snippets when they're no longer needed
The save command has two modes: saving specific lines or saving an entire file.
The standard save command allows you to store a snippet from specific lines in a file. You must specify the starting line number. For multi-line snippets, you can optionally specify an end line.
Full Command:
# For multiple lines
snippet save --tag <tag> --filepath <filepath> --startline <startline> --endline <endline>
# For a single line
snippet save --tag <tag> --filepath <filepath> --startline <startline>Short Form:
# For multiple lines
snippet save -t <tag> -f <filepath> -s <startline> -e <endline>
# For a single line
snippet save -t <tag> -f <filepath> -s <startline>Parameters:
tag: A unique identifier for your snippetfilepath: Path to the source filestartline: Starting line number of the snippet (required)endline: Ending line number of the snippet (optional, for multi-line snippets)
You can save the entire contents of a file as a snippet using the save all command. This doesn't require specifying line numbers.
Full Command:
snippet save all --file <filepath> --tag <tag>Short Form:
snippet save all -f <filepath> -t <tag>snippet listsnippet get --tag <tag>snippet copy --tag <tag>snippet delete --tag <tag>Save a single line:
snippet save --tag "log-function" --filepath cmd/snippet/main.go --startline 15Save multiple lines:
snippet save --tag "parse-options" --filepath cmd/snippet/main.go --startline 10 --endline 40Save an entire file:
snippet save all -t "main-function" -f main.goUsing short form:
# Single line
snippet save -t "error-handler" -f errors.go -s 25
# Multiple lines
snippet save -t "middleware" -f server.go -s 30 -e 45Get a saved snippet:
snippet get --tag "log-function"- Line numbers start at 1 (not 0)
- The
startlineparameter is always required when not usingsave all - For single-line snippets, omit the
endlineparameter - When
endlineis specified, both start and end lines are included in the snippet - Use
save allwhen you want to store the entire contents of a file