Github File and Link Tricks

2 tricks I learned today that I'd like to share: reliably linking to a specific line and searching for files using fuzzy matching.

Reliably link to a specific line

Say you are on the master branch, and you want to reference a line in a file. This could either be for a conversation you are having at that moment, answering a question in a PR, or adding information to a ticket. At that point in time, your link will work great. But, what about when that file gets changed tomorrow? More lines get added higher up, above the link, and the line that the link it pointing to, now points to something else!

You can easily have github switch to the latest commit for the file you are viewing. Just press 'y'. Then, when you link to a line, you are linking to THAT version of the file. You reference will always be intact.

Search for files using fuzzy matching

When you are browsing through files, there is a button in the upper right that says "Find file". I'm sure it's been there forever, but I just noticed it.

This brings you to a full file tree that you can search using fuzzy matching. Just like if you were in your IDE quick-opening a file!

Format JSON and save to gist with Alfred

At work, we have an Angular app that deals with a lot of custom JSON. With a distributed dev team, we pass a LOT of JSON around.  Copying from Chrome’s net tab, formatting, adding to a Github gist for easy transport is a PITA when you are doing it 20 times a day. I have 2 Alfred workflows to help with this.

My Use:

  1. Copy unformatted JSON to clipboard
  2. Alfred “JsonLint”. Formatted JSON is now in my clipboard
  3. Alfred “gist”. URL to raw gist is now in my clipboard
  4. One of these days I’ll chain these together

To get this working:

  1. You’ll need the Alfred PowerPack
  2. Install my JSON lint workflow. (It needs work, but gets the job done)
  3. Install AlfredGist

* Be sure to follow the setup instructions. * I prefer to have the ‘raw’ url returned from AlfredGist. (in the clipboard and opened)
To enable this, open
Look for this line: gist_url=$(get_json_key “html_url" "$json") Modify to: gist_url=$(get_json_key “raw_url” "$json")

  • In “gistconfig” set the gists to be private

You should now be able to chain together as I listed above

Let me know if you have any questions!