A simple CLI tool to download code snippets by user/slug
identifier from the SnippetLab API and save them to disk or stdout.
- Download a snippet by
user/slug
. - Automatically detect file name from HTTP
Content-Disposition
header. - Support for custom output path with automatic directory creation.
- Default API base URL is hardcoded for zero‑configuration installation.
Install globally with npm or pnpm:
npm install -g snippetlab
# or
pnpm add -g snippetlab
snippetlab add <user/slug> [output] [--base-url <url>]
-
<user/slug>
: required. Snippet identifier, e.g.aaron/usetoggle-hook
. -
[output]
: optional. File path to save the snippet. If omitted:- When running in a TTY, saves as the file name provided by the API header.
- When redirecting stdout (
>
), writes raw content to stdout.
-
--base-url
,-b
: optional. Override default API base URL (defaults tohttps://snippetlab.app
).
-
Save using header filename (TTY mode):
snippetlab add aaron/test-snippet # Creates file `test.js` in current directory
-
Redirect to custom file:
snippetlab add aaron/usetoggle-hook > code/index.ts # Writes raw content to stdout, redirected into `code/index.ts`
-
Specify output path:
snippetlab add aaron/usetoggle-hook myHooks/useToggle.ts # Creates `myHooks/useToggle.ts`, creating `myHooks/` if needed
-
Use local development server:
snippetlab add aaron/test-snippet --base-url http://localhost:3000 > demo.js
Option | Description | Default |
---|---|---|
--base-url |
API base URL for snippet service | https://snippetlab.app |
-
Clone the repo:
git clone [https://github.com/aaronperezaguilera/snippetlab-cli.git](https://github.com/aaronperezaguilera/snippetlab-cli.git) cd snippetlab
-
Install dependencies:
npm install # or pnpm install
-
Link locally for testing:
npm link
-
Run in local dev mode:
snippetlab add aaron/test-snippet --base-url http://localhost:3000
- Fork the repository.
- Create a branch:
git checkout -b feat/my-feature
. - Commit your changes:
git commit -m "feat: add my feature"
. - Push to your fork:
git push origin feat/my-feature
. - Open a pull request.