cli-snip-tool 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +506 -0
- package/dist/commands.js +440 -0
- package/dist/db.js +260 -0
- package/dist/edit.js +171 -0
- package/dist/editor.js +23 -0
- package/dist/index.js +64 -0
- package/dist/schema.js +88 -0
- package/dist/utils.js +5 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 satyamsinghs408
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
# snip — A personal code snippet manager for your terminal
|
|
2
|
+
|
|
3
|
+
> Save, search, and copy your most-used code snippets without leaving the terminal.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## The problem
|
|
12
|
+
|
|
13
|
+
Every developer re-searches the same commands over and over.
|
|
14
|
+
|
|
15
|
+
- "What was that `docker exec` command again?"
|
|
16
|
+
- "How do I force-push safely in git?"
|
|
17
|
+
- "What's the `curl` flag for sending JSON headers?"
|
|
18
|
+
|
|
19
|
+
You either Google it for the 10th time, dig through your shell history, or scroll through old Notion notes.
|
|
20
|
+
|
|
21
|
+
**snip fixes that.** It gives you a personal, searchable library of code snippets that lives in your terminal — no browser, no internet, no account needed.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
snip find "docker exec" --copy
|
|
25
|
+
# ✔ Copied "Docker exec into container" to clipboard
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Features
|
|
31
|
+
|
|
32
|
+
- **Full-text search** — searches title, code, and description all at once
|
|
33
|
+
- **Tag system** — organize snippets by topic like `docker`, `git`, `sql`
|
|
34
|
+
- **Language filter** — filter by `bash`, `javascript`, `python`, and more
|
|
35
|
+
- **Opens your editor** — paste code in vim, nano, or vscode — whatever you use
|
|
36
|
+
- **Clipboard copy** — one command to copy any snippet
|
|
37
|
+
- **Usage tracking** — see which snippets you actually use most
|
|
38
|
+
- **Export and import** — back up and restore your library as JSON or Markdown
|
|
39
|
+
- **Works offline** — everything stored locally in a single SQLite file
|
|
40
|
+
- **Zero config** — just install and start saving
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
### Requirements
|
|
47
|
+
|
|
48
|
+
- Node.js 18 or higher
|
|
49
|
+
- npm
|
|
50
|
+
|
|
51
|
+
### Install globally
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm install -g snip-cli
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
After that, the `snip` command is available everywhere in your terminal.
|
|
58
|
+
|
|
59
|
+
### Verify it works
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
snip --help
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
You should see a list of all available commands.
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## Quick start — your first snippet
|
|
70
|
+
|
|
71
|
+
### Step 1 — Save a snippet
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
snip add
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The terminal will ask you a few questions:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
? Snippet title: Docker exec into container
|
|
81
|
+
? Language: bash
|
|
82
|
+
? Description (optional): Exec into a running Docker container interactively
|
|
83
|
+
? Select existing tags: (none yet)
|
|
84
|
+
? Add new tags: docker, devops
|
|
85
|
+
|
|
86
|
+
Opening your editor — save and close when done…
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Your editor opens. Paste your code:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
docker exec -it $1 /bin/bash
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Save and close the editor. Done — your snippet is saved.
|
|
96
|
+
|
|
97
|
+
### Step 2 — Find and copy it
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
snip find "docker exec" --copy
|
|
101
|
+
# ✔ Copied "Docker exec into container" to clipboard
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Now paste it anywhere with `Ctrl+V`.
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## All commands
|
|
109
|
+
|
|
110
|
+
### `snip add` — Save a new snippet
|
|
111
|
+
|
|
112
|
+
Opens an interactive prompt that asks for the title, language, tags, and code.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
snip add
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
You can also skip the prompts with flags:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
snip add --title "Docker exec" --language bash --tags docker,devops
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Or pipe code directly from a file (no editor opens):
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
cat deploy.sh | snip add --stdin --title "Deploy script" --language bash
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Available flags:**
|
|
131
|
+
|
|
132
|
+
| Flag | What it does |
|
|
133
|
+
|---|---|
|
|
134
|
+
| `--title <text>` | Set the title directly |
|
|
135
|
+
| `--language <lang>` | Set the language directly |
|
|
136
|
+
| `--tags <list>` | Comma-separated tags |
|
|
137
|
+
| `--stdin` | Read code from piped input instead of editor |
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### `snip find` — Search your snippets
|
|
142
|
+
|
|
143
|
+
The most useful command. Searches everything — title, code, and description.
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
snip find "docker exec"
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
This shows a list of matching snippets, then a picker where you can choose to copy, preview, or edit one.
|
|
150
|
+
|
|
151
|
+
**Copy the top result immediately (no picker):**
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
snip find "docker exec" --copy
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
**Filter by tag:**
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
snip find --tag docker
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Filter by language:**
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
snip find --language bash
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Combine search and filter:**
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
snip find "exec" --tag docker --language bash
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**Pipe directly to run:**
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
snip find "deploy script" --copy | bash
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Available flags:**
|
|
182
|
+
|
|
183
|
+
| Flag | What it does |
|
|
184
|
+
|---|---|
|
|
185
|
+
| `--copy` | Copies top result to clipboard, no picker |
|
|
186
|
+
| `--tag <name>` | Filter results by tag |
|
|
187
|
+
| `--language <lang>` | Filter results by language |
|
|
188
|
+
| `--limit <n>` | How many results to show (default: 10) |
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
### `snip list` — See all your snippets
|
|
193
|
+
|
|
194
|
+
Shows every snippet in a table format.
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
snip list
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Example output:
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
#1 Docker exec into container bash [docker, devops] copied 12×
|
|
204
|
+
#2 JWT decode in Node.js js [auth, jwt] copied 8×
|
|
205
|
+
#3 Nginx restart command bash [nginx, devops] copied 5×
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Filter by tag:**
|
|
209
|
+
|
|
210
|
+
```bash
|
|
211
|
+
snip list --tag devops
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
---
|
|
215
|
+
|
|
216
|
+
### `snip copy` — Copy a snippet by its id
|
|
217
|
+
|
|
218
|
+
If you already know the id number, this is the fastest way to copy.
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
snip copy 3
|
|
222
|
+
# ✔ Copied "Nginx restart command" to clipboard
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
You can find id numbers by running `snip list`.
|
|
226
|
+
|
|
227
|
+
**Run the snippet directly:**
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
snip copy 3 | bash
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
### `snip edit` — Edit an existing snippet
|
|
236
|
+
|
|
237
|
+
Opens a menu to choose which field to edit — code, title, tags, or description.
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
snip edit 3
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
The terminal asks:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
? What do you want to edit?
|
|
247
|
+
◉ Code (opens editor)
|
|
248
|
+
○ Title
|
|
249
|
+
○ Tags
|
|
250
|
+
○ Description
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
For code — your editor opens with the current code pre-filled. Edit it, save, and close.
|
|
254
|
+
|
|
255
|
+
**Edit only the title (skips the menu):**
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
snip edit 3 --title
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Edit only the tags:**
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
snip edit 3 --tags
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**Available flags:**
|
|
268
|
+
|
|
269
|
+
| Flag | What it does |
|
|
270
|
+
|---|---|
|
|
271
|
+
| `--title` | Edit title only |
|
|
272
|
+
| `--tags` | Edit tags only |
|
|
273
|
+
| `--description` | Edit description only |
|
|
274
|
+
|
|
275
|
+
---
|
|
276
|
+
|
|
277
|
+
### `snip delete` — Delete a snippet
|
|
278
|
+
|
|
279
|
+
Permanently removes a snippet. Asks for confirmation first.
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
snip delete 3
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
```
|
|
286
|
+
Delete "Nginx restart command"? (Y/n): Y
|
|
287
|
+
# ✔ Snippet #3 deleted.
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
> There is no undo. Run `snip export` first if you are unsure.
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
### `snip top` — See your most-used snippets
|
|
295
|
+
|
|
296
|
+
Shows the top 10 snippets ranked by how many times you have copied them.
|
|
297
|
+
|
|
298
|
+
```bash
|
|
299
|
+
snip top
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Example output:
|
|
303
|
+
|
|
304
|
+
```
|
|
305
|
+
#1 Docker exec into container bash copied 24×
|
|
306
|
+
#7 Git force push safely bash copied 18×
|
|
307
|
+
#2 JWT decode in Node.js js copied 11×
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Useful for knowing what to put in your shell aliases.
|
|
311
|
+
|
|
312
|
+
---
|
|
313
|
+
|
|
314
|
+
### `snip export` — Back up your snippets
|
|
315
|
+
|
|
316
|
+
Exports all snippets to a file. Use this to back up your library or move to a new machine.
|
|
317
|
+
|
|
318
|
+
**Export as JSON (for importing back later):**
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
snip export --format json
|
|
322
|
+
# ✔ Exported 42 snippets → snippets-2026-06-24.json
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
**Export as Markdown (human-readable, good for sharing):**
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
snip export --format md
|
|
329
|
+
# ✔ Exported 42 snippets → snippets-2026-06-24.md
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
---
|
|
333
|
+
|
|
334
|
+
### `snip import` — Restore snippets from a file
|
|
335
|
+
|
|
336
|
+
Reads a JSON export file and adds snippets to your database. Skips duplicates automatically, so it is safe to run more than once.
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
snip import snippets-2026-06-24.json
|
|
340
|
+
# ✔ Imported 42 snippets.
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**Moving to a new machine:**
|
|
344
|
+
|
|
345
|
+
```bash
|
|
346
|
+
# On your old machine
|
|
347
|
+
snip export --format json
|
|
348
|
+
|
|
349
|
+
# Copy the file to the new machine, then
|
|
350
|
+
snip import snippets-2026-06-24.json
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
---
|
|
354
|
+
|
|
355
|
+
## Real-world examples
|
|
356
|
+
|
|
357
|
+
### Save a git shortcut you always forget
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
snip add --title "Git undo last commit (keep changes)" --language bash --tags git
|
|
361
|
+
# Editor opens → type: git reset --soft HEAD~1
|
|
362
|
+
# Save and close
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### Save a curl command with JSON headers
|
|
366
|
+
|
|
367
|
+
```bash
|
|
368
|
+
snip add --title "curl POST with JSON" --language bash --tags curl,api
|
|
369
|
+
# Editor opens → type:
|
|
370
|
+
# curl -X POST https://api.example.com/endpoint \
|
|
371
|
+
# -H "Content-Type: application/json" \
|
|
372
|
+
# -H "Authorization: Bearer YOUR_TOKEN" \
|
|
373
|
+
# -d '{"key": "value"}'
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Save a multi-line bash script
|
|
377
|
+
|
|
378
|
+
```bash
|
|
379
|
+
cat cleanup.sh | snip add --stdin --title "Cleanup node_modules" --language bash --tags node
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
### Find and use it later
|
|
383
|
+
|
|
384
|
+
```bash
|
|
385
|
+
snip find "cleanup" --copy
|
|
386
|
+
# Paste and run wherever you need it
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
### Save a SQL query you run often
|
|
390
|
+
|
|
391
|
+
```bash
|
|
392
|
+
snip add --title "Find duplicate emails in users table" --language sql --tags sql,postgres
|
|
393
|
+
# Editor opens → paste your query
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
---
|
|
397
|
+
|
|
398
|
+
## How it stores your data
|
|
399
|
+
|
|
400
|
+
snip stores everything locally on your machine — no cloud, no server, no account.
|
|
401
|
+
|
|
402
|
+
| What | Where |
|
|
403
|
+
|---|---|
|
|
404
|
+
| Database file | `~/.config/snip/snip.db` |
|
|
405
|
+
| Config | `~/.config/snip/config.json` |
|
|
406
|
+
|
|
407
|
+
The database is a standard SQLite file. You can open it with any SQLite browser if you ever want to inspect it directly.
|
|
408
|
+
|
|
409
|
+
To delete everything and start fresh:
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
rm -rf ~/.config/snip
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
## Set your preferred editor
|
|
418
|
+
|
|
419
|
+
snip uses the `$EDITOR` environment variable to know which editor to open.
|
|
420
|
+
|
|
421
|
+
**Check what is currently set:**
|
|
422
|
+
|
|
423
|
+
```bash
|
|
424
|
+
echo $EDITOR
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
**Set it in your shell config (`~/.bashrc` or `~/.zshrc`):**
|
|
428
|
+
|
|
429
|
+
```bash
|
|
430
|
+
# For VS Code
|
|
431
|
+
export EDITOR="code --wait"
|
|
432
|
+
|
|
433
|
+
# For vim
|
|
434
|
+
export EDITOR="vim"
|
|
435
|
+
|
|
436
|
+
# For nano
|
|
437
|
+
export EDITOR="nano"
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
Then reload your shell:
|
|
441
|
+
|
|
442
|
+
```bash
|
|
443
|
+
source ~/.zshrc
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
> The `--wait` flag for VS Code is important. Without it, the editor opens and snip thinks you closed it immediately — your code will not be saved.
|
|
447
|
+
|
|
448
|
+
---
|
|
449
|
+
|
|
450
|
+
## Tech stack
|
|
451
|
+
|
|
452
|
+
Built with:
|
|
453
|
+
|
|
454
|
+
- **TypeScript** — fully typed codebase
|
|
455
|
+
- **Node.js** — runtime
|
|
456
|
+
- **SQLite (better-sqlite3)** — local database with full-text search (FTS5)
|
|
457
|
+
- **Commander.js** — CLI command parsing
|
|
458
|
+
- **Inquirer.js** — interactive terminal prompts
|
|
459
|
+
- **Chalk** — terminal colors
|
|
460
|
+
- **Clipboardy** — cross-platform clipboard access
|
|
461
|
+
|
|
462
|
+
---
|
|
463
|
+
|
|
464
|
+
## Contributing
|
|
465
|
+
|
|
466
|
+
Contributions are welcome. To run the project locally:
|
|
467
|
+
|
|
468
|
+
```bash
|
|
469
|
+
# Clone the repo
|
|
470
|
+
git clone https://github.com/satyamsinghs408/cli-snippet-manager.git
|
|
471
|
+
cd snip-cli
|
|
472
|
+
|
|
473
|
+
# Install dependencies
|
|
474
|
+
npm install
|
|
475
|
+
|
|
476
|
+
# Build
|
|
477
|
+
npm run build
|
|
478
|
+
|
|
479
|
+
# Link globally so you can test the snip command
|
|
480
|
+
npm link
|
|
481
|
+
|
|
482
|
+
# Run in dev mode (no build needed, uses tsx)
|
|
483
|
+
npm run dev
|
|
484
|
+
```
|
|
485
|
+
|
|
486
|
+
To run the test suite:
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
npm test
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
Please open an issue before submitting a large pull request so we can discuss the approach first.
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
496
|
+
## Licence
|
|
497
|
+
|
|
498
|
+
MIT — free to use, modify, and distribute.
|
|
499
|
+
|
|
500
|
+
---
|
|
501
|
+
|
|
502
|
+
## Author
|
|
503
|
+
|
|
504
|
+
Built by [Satyam Singh](https://github.com/satyamsinghs408)
|
|
505
|
+
|
|
506
|
+
If this saved you time, consider giving the repo a star on GitHub.
|