I recently came across the need for this after watching the Railscasts episode 402

The functionality that Ryan showed is apparently available out of the box to Mac users. That is the ability to open SublimeText2 using a custom protocol in better_errors

I figured it was possible to do this on linux, but I wasn’t sure how much effort it would be to accomplish.

In a nutshell, better_errors provides links such as

sublime:///home/tim/Documents/Coding/portfolio/README.md

Which your browser will then open automatically for you, using the appropriate application. TextMate folks get this for free on OSX I guess.

Anyways, to do it, you need to edit/create some files.

  • /home/tim/.local/share/applications/mimeapps.list
  • /home/tim/.local/share/applications/sublime.desktop
  • /home/tim/Applications/SublimeText2/sublime

You will likely need to create the second and third files there. Also, change your home directory to be that of your username.

The content of the files is shown in this gist.

For the mimeapps.list file, you will want to append the data to that file since it is likely to already contain a lot of entries. Append it under the header that I show in the gist.

For the sublime.desktop file, be sure to change the path to your SublimeText2 installation. The full path is required or else it will not work in your browser.

For the sublime file, again, be sure it points to your installation. The $2 there represents the second argument sent to the script. This will be the name of the file; -a (from sublime.desktop) will be in $1.

The reason you need the wrapper script is because sublime apparently doesn’t interpret the “sublime://” prefix correctly when it receives the file. It opens a new file called “sublime”. I suspect it has something to do with their logic for parsing the line number that you want to jump to (which is prefixed with a colon).

You can verify that it works by using the xdg-open command. Like so

xdg-open sublime:///path/to/some/file

You should not receive an error window. Instead, sublime should open normally.

Now, to use it in Chrome, follow a link that contains the sublime:// protocol. For instance, this one. You may be presented with a window that looks similar to this google-chrome-xdg-open

For the first time that you launch it, click Launch Application, but do not check the checkbox. If you do, and things don’t work, you’ll be mighty confused and need to edit your Local State file in Chrome to fix it.

If the application opens fine, then click the link again and check the box to make it permanent.

Hope that helps