Over 20 years of writing scripts and apps I’ve collected a lot of “snippets” of code that I save whenever I solve a problem and think I’ll want the solution again in the future. I like these snippets to include notes and links, and I need to be able to easily search them and grab the code when I need it without much effort. That’s why I wrote Snibbets back in 2020.
I’ve now refactored Snibbets as a gem and vastly improved its capabilities. I wanted the simplicity of creating snippets in nvUltra and searching them quickly from the command line, getting just the code I need with a few keystrokes. I keep iTerm in Visor mode, so it’s a hotkey away, and just as convenient as any quick find panel in a dedicated snippet management app.
Snibbets now has its own project page where you can read all about its features and options. You can also see all the code, file bug reports, and make feature requests on GitHub.
Here’s a quick overview, though.
Snippets Are Markdown Files
A snippet is just a Markdown file, where the filename becomes the title, optionally with additional extensions that help the syntax highlighter, e.g. symbolize hash keys.rb.md
. The document can contain tags in MultiMarkdown metadata format, titles as #
headlines, additional notes, and the code snippet either indented or fenced with optional language specifier. A single document can contain multiple snippets, separated with headlines as titles for each one.
Snippets all go into one folder. You don’t need to organize them into directories, that would defeat the purpose of the full text search in Snibbets. You can open that directory in any app that can handle it, such as nvUltra or Obsidian, and have full access for editing and creating new snippets.
Searching Your Snippets
To search your snippets, just run snibbets SEARCH TERMS
. It will use a combination of Spotlight, find
, and grep
to find matches. If there’s more than one match, you’ll get a menu, and if the selected file contains more than one snippet, you’ll get a second menu. The code from the snippet is output to the console without any accompanying notes.
You can run with --edit
to open the selected snippet in your editor to see all of the notes or update the code. You can also use --nvultra
to open the snippet in nvUltra, assuming you’re on the beta. You can also run with --copy
to copy just the code to your clipboard in addition to displaying it in the console. Run snibbets -h
to see all available options.
Filtering
When multiple results/snippets are detected, a menu is generated. If you have fzf installed, it will be used for the menu, allowing fuzzy searching to narrow results. If you don’t have fzf but do have gum installed, that will be used and is almost as good for this purpose. Failing that, Snibbets will generate its own menu and you’ll have to enter a number to get the snippet. fzf and gum are far superior, so I recommend installing one or the other.
Syntax Highlighting
I put a lot of time into syntax highlighting. You can use either Pygments or Skylighting (separate installations), and you can configure the theme. Syntax definitions are picked up from the filename and from language specifiers on fenced code blocks. It looks really great using Skylighting and the Nord theme (as shown in the video above). To enable this, edit your config (snibbets --configure
) to include:
highlight: true
highlighter: skylighting
highlight_theme: nord
Snibbets will avoid highlighting anything going to the clipboard or being piped or redirected to other commands. Keeps things tidy.
It’s a simple tool1, but it makes it feasible for me to store all of my code snippets in a way that allows nvUltra to become my main code snippet manager, and gives me instant access to any snippet from the command line. Just what I needed.
Check out the project page or see it on GitHub.
-
though you wouldn’t know it based on the number of hours I’ve put into it lately. ↩