Skip to content

Instantly share code, notes, and snippets.

@wojtha
Forked from stevenpetryk/sb2-better_errors.md
Last active December 12, 2015 09:09
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wojtha/4749450 to your computer and use it in GitHub Desktop.
Save wojtha/4749450 to your computer and use it in GitHub Desktop.

Using better_errors on Ubuntu with SublimeText 2

After I installed the fantastic better_errors gem, I was disappointed to notice that linking to your text editor doesn't work correctly on Ubuntu (at least, it didn't for me). Here's how I fixed it.

First, create a new desktop entry:

# /usr/share/applications/subl-urlhandler.desktop

[Desktop Entry]
Version=1.0
Name=Sublime Text 2
Name[en_PH]=Sublime Text 2
Exec=/usr/bin/subl-urlhandler %u
Icon=/opt/subl/Icon/48x48/sublime_text.png
Terminal=false
Type=Application
Categories=Development;
StartupNotify=true
MimeType=x-scheme-handler/subl;

Next, let's create the script we're linking to.

#!/bin/bash
# /usr/bin/subl-urlhandler

request=${1:23}               # Delete the first 23 characters
request=${request//%2F//}     # Replace %2F with /
request=${request/&line=/:}   # Replace &line= with :
request=${request/&column=/:} # Replace &column= with :

# Launch sublime
sublime $request       # Launch ST2

Make the url handler executable: sudo chmod +x /usr/bin/subl-urlhandler.

Finally, reload your desktop files by running: sudo update-desktop-database.

Now you should be good to go! I hope this helped!

@johnjohndoe
Copy link

Make sure you check if sublime is available as a command. On my machine I use subl $request to launch Sublime Text 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment