Skip to content

Custom Prefix Configuration (Ubuntu, Sublime, and Firefox)

Michael Chau edited this page May 17, 2014 · 2 revisions

In order to open links with a custom prefix in Firefox (tested on Ubuntu), a few things must be configured.

Configure MetricFu

.metrics should have the prefix set:

MetricFu::Configuration.run do |config|
  config.templates_configuration do |tc|
    tc.link_prefix = 'sublime:/'
  end
end

This will append a prefix of sublime:/// when you click any of the file links.

Configure Firefox

Most likely Firefox won't know what to do with this sublime:/// protocol. It'll probably say something a long the lines of: The address wasn't understood.

  1. In your url bar go to: about:config
  2. Right click somewhere and select new in the context menu and select boolean
  3. Preference name should be network.protocol-handler.expose.sublime
  4. Value should be set to false

Now that you've added this custom protocol, next time you click a link with sublime:/// it will ask you what application to launch it with.

However, selecting Sublime won't work because it will try to read it from the sublime:/// location. So we need to write a script to strip out the protocol and then open it in Sublime.

Configuring a Sublime Url Handler Script

Create a new subl-urlhandler.desktop file inside /usr/share/applications.

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

When Firefox asks us what application we want to launch when using the sublime: protocol, we can select subl-urlhandler by browsing /usr/bin/applications.

Now we need to configure the actual script.

Create /usr/bin/subl-urlhandler:

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

request=${1:10}               # Delete the first 10 characters

# Launch sublime
subl $request       # Launch ST2

We just need to remove sublime://, which is the first 10 characters. Replace subl if you have it configured to use sublime.

Done

Now run metric_fu in your terminal, go to a section and click a file link. Firefox will ask you what you want to launch the application with, browse and go to /usr/bin/applications/subl-urlhandler.desktop.

Notes / Sources:

  1. MozillaZine: Register Protocol - Registering a protocol in Firefox
  2. Gist: Using Sublime Text 2 with better_errors on Ubuntu - Referenced this script that was originally configured to be used with better_errors