Skip to content

Instantly share code, notes, and snippets.

@fenprace
Last active December 12, 2015 02:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fenprace/4697254 to your computer and use it in GitHub Desktop.
Save fenprace/4697254 to your computer and use it in GitHub Desktop.
Hacked xdg-open to support "subl://" for linux.
#!/bin/sh
sudo mv /usr/bin/xdg-open /usr/bin/xdg-open.bak
sudo curl https://gist.github.com/raw/4697254/16b3ce7ae4c4e63162ca0d9e47b2805d410bfa14/xdg-open.rb -o /usr/bin/xdg-open
sudo chmod a+x /usr/bin/xdg-open
#!/usr/bin/env ruby
require 'cgi'
require 'uri'
def parse(text)
uri = URI(text)
info = CGI::parse uri.query
info['url'] = URI(info['url'][0]).path
info
end
def launch(path, line)
system "subl #{path}:#{line}"
end
address = ARGV.first
if address =~ /^subl\:\/\//
result = parse(address)
launch result['url'], result['line']
else
system "/usr/bin/xdg-open.bak #{address}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment