10

How can I make sublime text 2 respond to txmt url scheme in ubuntu? This has been possible in OSX through subl-handler and in Windows through SublimeProtocol.

3 Answers 3

20

I asked me the same question today, seeing the txmt protocol with "better_errors" gem for Rails.

I search a long time but found nothing, so I tried to make it by myself.

I write an article and my blog, but I copy it here, for "future-proofness" :

Step 1

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

[Desktop Entry]
Name=Sublime Text 2 URL Handler
GenericName=Text Editor
Comment=Handle URL Scheme txmt://
Exec=/home/<your_user>/bin/sublime-handler %u
Terminal=false
Type=Application
MimeType=x-scheme-handler/txmt;
Icon=sublime-text-2
Categories=TextEditor;Development;Utility;
Name[en_US]=Sublime Text 2 URL Handler

Step 2: Update the MIME-types database

$ sudo update-desktop-database

Step 3: Create the ~/bin/sublime-handler file

#!/usr/bin/env bash

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 :
sublime-text-2 $request       # Launch ST2

Then make it executable : $ chmod +x ~/bin/sublime-handler

Step 4: Test a txmt:// file

If that dosen't work, say me, I'll try to help you.

Sign up to request clarification or add additional context in comments.

2 Comments

from Chrome or from console(xdg-open txmt://open?url=file://%2Fhome%2Fguda%2Fclub50plus%2Fapp%2Fadmin%2Fdashboard.rb&line=26) I aways get a new browser window opened. Any ideas why?
Needs an additional step: xdg-mime default sublime-handler.desktop x-scheme-handler/subl
2

Adding an answer, because I don't have enough reputation for a comment.

For Ubuntu 14.04, Sublime Text 3, the instructions above work. Thank you so much, @ByScripts!

In Step 3, replace:

sublime-text-2 $request # Launch ST2

with:

subl $request # Launch ST3

... and don't forget to add your own username in Step 1:

Exec=/home/<your_user>/bin/sublime-handler %u

Comments

0

I don't have the reputation to comment, but I would like to add to the accepted answer, that you'll need to also configure your browser to open txmt files with the new ~/bin/sublime-handler

I saved my handler in /usr/bin, which also works btw.

To configure Firefox:

  1. go to Edit > Preferences > Applications or enter the following into the URI field about:preferences#applications
  2. search for txmt
  3. on the txmt entry click on the action field and browse for your sublime-handler file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.