Code search Alfred workflow

Code search is a useful tool to search for examples about some function, class, etc. We're going to create a Alfred workflow to easily search into GitHub Code search and SourceGraph

Create a workflow

Let's go to Alfred settings/Workflows/+/Blank workflow


Name our new workflow, you can use whatever name you want, let's put "Code search"


Create a new element of type script filter


Now we need to make some adjustments over the defaults values:

  • keyword, we use cs for easy access
  • Language /bin/bash
  • with input as {query}

And we need to put the following code into script box:

cat << EOF
  "items": [
      "title": "GitHub code search",
      "arg": "{query}"
      "title": "SourceGraph",
      "arg": "{query}&patternType=standard"

Here we're just printing a JSON file with the options to be selected, we now support 2 services:

  • GitHub Code Search
  • SourceGraph

In case we need to add another one we can do it here.

The resulting configuration should be like the below image:


Open the browser using the selected service

Now we need to define an action to open an URL in the browser


We leave all the defaults here because the script filter (defined in the previous step) will generate the URL.

Linking all together

Now we need to link both components, we use the graphic tool in Alfred, the result should be as the following image:



Now if we open Alfred and write for example: cs completing-read we'll see the following image:


If we press enter a new browser tab will be open with the selected service and input we wrote.

Enjoy :)