DEV Community

ke jia
ke jia

Posted on

Copy-Paste Is a Workflow. I Gave It a Search Box.

Ask any senior engineer where their best snippets live. You'll get a list: browser history, a Slack thread from 2023, a Notes app entry, the README of a dead project, Stack Overflow, and "somewhere in my head."

That's not a snippet library. That's a crime scene.

I got tired of re-deriving the same awk one-liners, the same Nginx redirect blocks, the same retry loops. So I set one rule: if I'm about to paste something for the second time, it earns a name.

The tool doing the holding is snippetx — a zero-dependency terminal snippet manager. Single Node file, no server, no account. Your snippets live in a local directory, and the manager never phones home.

The three commands that matter

Save (pipe anything in):

$ echo 'app.get("/health", (req, res) => res.json({ok: true}))' | snippetx add health-route js
$ echo 'kubectl logs -n prod $(kubectl get pods -n prod -l app=api -o jsonpath="{.items[0].metadata.name}")' | snippetx add prod-logs sh
Enter fullscreen mode Exit fullscreen mode

Search (this is the whole point):

$ snippetx search kubectl
a1b2c3d4  prod-logs   sh   kubectl logs -n prod $(kubectl get pods ...
Enter fullscreen mode Exit fullscreen mode

Copy (to stdout, which means it composes with everything):

$ snippetx copy a1b2c3d4 | pbcopy
Enter fullscreen mode Exit fullscreen mode

That last line is the one that made it stick. snippetx copy <id> prints the snippet to stdout, so it's just another pipe stage. It works with pbcopy on macOS, clip.exe on Windows, xclip on Linux, and — most usefully — directly into another command:

$ docker run -i --rm alpine cat > /app/entrypoint.sh < <(snippetx copy entrypoint)
Enter fullscreen mode Exit fullscreen mode

The library that actually gets used

After a few months, the library has ~200 entries and a shape that surprised me:

  • The top 20 entries get 90% of the lookups. The long tail is a graveyard of snippets I'll never touch. That's fine — the cost of keeping them is zero, and search doesn't care.
  • Names are verbs, not nouns. prod-logs beats useful-k8s-thing. If I can't name it in two words, I don't remember what it does either.
  • Language tags are lazy but useful. js, sh, sql, yaml. Filtering by tag in snippetx list keeps the firehose manageable.

Why terminal, why local

I've used the cloud snippet services. They're fine until you notice the pattern: every one of them is a SaaS with a mobile app, a sync engine, and a business model that is not "storing your Nginx config."

snippetx's entire feature list fits on a napkin:

add <name> [lang]   save (pipe content in)
list [filter]       list all snippets
show <id>           view a snippet
search <term>       search all snippets
rm <id>             delete
copy <id>           output to stdout
Enter fullscreen mode Exit fullscreen mode

No sync means no conflict resolution. No cloud means nothing to revoke when you leave a team. And "zero dependencies, single file" means the tool itself can't be the thing that breaks your workflow at 6pm.

The rule is the product

Honestly, the tool is the easy part. The part that changed my workflow is the rule: second paste = named snippet. It turns copy-paste from an accident into a searchable asset, and it takes about two seconds per save.

Your browser history will outlive you. Your snippet library can too — if it lives somewhere you can grep.

$ npx @wuchunjie/snippetx
Enter fullscreen mode Exit fullscreen mode

More Tools

Tool What it does Command
scaffoldx-cli 12 production-ready project templates in 3 seconds npx scaffoldx-cli
dotguard Scan .env files for exposed secrets npx @wuchunjie/dotguard
gitpulse Git repo analytics in your terminal npx @wuchunjie/gitpulse
snippetx Terminal code snippet manager npx @wuchunjie/snippetx

If these save you time, consider buying me a coffee. All tools are MIT-licensed, zero-dependency, and run fully offline.

Top comments (0)