Creating an Alfred Workflow to open GitHub repos
I’ve written a script which lets me build an Alfred workflow to open GitHub repositories quickly. I type a few characters in the launcher, and it offers to open the repo:
You don’t need a custom workflow to do this – Alfred already has built-in features for web search and using bookmarks – but to set those up, you have to click around in the GUI. At work, our code is scattered across a lot of different repositories, and I find it easier to manage with a script.
This also allows me to get similar GitHub shortcuts at work and at home. I can’t use Alfred’s built-in preference syncing because I have no shared file sync between my personal and professional machines; I try to keep them isolated. Defining these bookmarks in a workflow I can build separately on each Mac gets me consistent behaviour, wherever I’m working.
I define my repos in an ini-like config file:
[repos] alexwlchan = docstore dominant_colours pathscripts wellcomecollection = wellcomecollection.org (dotorg) storage-service scanamo = scanamo
This is slightly abusing the file format used by Python’s configparser module; this is a series of key-value pairs in which the values are multi-line strings that get broken up within the script.
The Python script reads this config and builds a workflow package, which I can open in Alfred:
The text-based config means I can add and remove repos very quickly. I don’t have a shortcut for every repo I use; just the ones in which I’m actively working. I open GitHub dozens of times a day, and I use these shortcuts a similar amount.
I don’t know how many other people will want this exact shortcut, but there might still be some ideas here you can reuse: in particular the multi-line values in a configparser file, and programatically creating an Alfred Workflow with Python.