A long while back I linked a CLI called
howdoi. It’s an excellent little tool that searches StackOverflow for code examples for any given query. It recently updated, so I thought I’d try my hand at a LaunchBar action for it.
There’s already an Alfred workflow, if you’re looking for that.
This action requires two things: the
howdoi CLI, and
pygmentize from the pygments package. Both of these can be installed with Homebrew:
brew install howdoi pygments
Once those are installed, just download and double-click the action below to install it. When you run it, it will ask for your query. Assuming it finds a result, it will offer you the option of viewing a syntax-highlighted version of it, copying the raw code to the clipboard, opening the source URL, or saving the query to the
howdoi cache. I’m not sure about the utility of the latter option, and setting up the cache requires manually creating a
~/.keep directory. But I figured I’d cover the bases.
Technical details: To do the preview I had it write the code out to a temp file, run
pygmentize on it with
-g to guess the lexer and
-f html to output HTML, then write out a style and the formatted code to another temp file. That temporary HTML file is passed back to LaunchBar with an item action to open QuickLook on it.