How to set subl:// protocol handler with Unity?

To register custom protocol handler in chrome

1. Create the desktop file

Create the file /usr/share/applications/sublime-handler.desktop

[Desktop Entry]
Name=Sublime Text 2 URL Handler
GenericName=Text Editor
Comment=Handle URL Scheme subl://
Exec=/usr/share/handlers/sublime-handler %u
Terminal=false
Type=Application
MimeType=x-scheme-handler/subl;
Icon=sublime-text-2
Categories=TextEditor;Development;Utility;
Name[en_US]=Sublime Text 2 URL Handler

2. Update the MIME-types database

$ sudo update-desktop-database

3. Create the handler file

Create the file /usr/share/handlers/sublime-handler

#!/usr/bin/env bash

request="${1#*://}"             # Remove schema from url (subl://)
request="${request#*?url=}"     # Remove open?url=
request="${request//%2F//}"     # Replace %2F with /
request="${request/&line=/:}"   # Replace &line= with :
request="${request/&column=/:}" # Replace &column= with :

subl "$request"                 # Launch sublime

Make it executable:

$ sudo chmod +x /usr/share/handlers/sublime-handler

4. Register mime-type handler

$ xdg-mime default /usr/share/applications/sublime-handler.desktop x-scheme-handler/subl

5. Profit

Now you can open links with custom protocols from chrome via custom applications, example:

subl:///home/path/to/file.php:123
subl://open?url=/home/path/to/file.php:123
subl://open?url=/home/path/to/file.php&line=123
subl://open?url=/home/path/to/file.php&column=123
subl://open?url=%2Fhome%2Fpath%2Fto%2Ffile.php&line=123
subl://open?url=%2Fhome%2Fpath%2Fto%2Ffile.php&column=123

6. Modify

It can be ported for using with the different IDE, for example phpstorm

Tags:

Unity

14.04