Last active
December 13, 2015 18:29
-
-
Save TylerRick/4955795 to your computer and use it in GitHub Desktop.
For opening links from better_error and RailsPanel in vim on Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Desktop Entry] | |
Encoding=UTF-8 | |
Name=Vim (Console) | |
Comment=Edit text files in a console using Vim | |
Exec=/usr/local/bin/open_txmt_link_in_vim %U | |
Terminal=false | |
Type=Application | |
Icon=/usr/src/vim/runtime/vim48x48.xpm | |
Categories=Application;Utility;TextEditor; | |
MimeType=text/plain;x-scheme-handler/vim;x-scheme-handler/txmt; | |
StartupNotify=true | |
StartupWMClass=open_txmt_link_in_vim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
#/usr/local/bin/open_txmt_link_in_vim | |
# Handler for the 'txmt:' schema that opens these links in console vim. | |
require 'uri' | |
require 'cgi' | |
# Create a log file. Useful for debugging (to know what args this command was called with) since | |
# this is executed non-interactively by xdg-open: | |
require 'pathname' | |
dir = Pathname("#{ENV['HOME']}/tmp").tap {|dir| dir.mkpath } | |
log = (dir + "#{File.basename($0)}.log").open('a') | |
log.puts '='*100 | |
log.puts Time.now | |
log.puts ARGV | |
begin | |
exit unless ARGV[0] | |
uri = URI.parse(ARGV[0]) | |
log.puts %(uri=#{(uri).inspect}) | |
exit unless uri.host == 'open' | |
exit unless uri.query | |
command = 'gnome-terminal -x vim --servername vim --remote-tab-silent' | |
params = CGI.parse(uri.query) | |
log.puts %(params=#{(params).inspect}) | |
if params['line'] | |
line = params['line'][0] | |
command << " +#{line}" | |
end | |
exit unless params['url'] | |
log.puts %(params['url'][0]=#{(params['url'][0]).inspect}) | |
url_param = URI.parse(params['url'][0]) | |
log.puts %(url_param=#{(url_param).inspect}) | |
exit unless url_param.scheme == 'file' | |
command << %Q[ "#{url_param.path}"] | |
log.puts %(command=#{command}) | |
log.puts `#{command}` | |
rescue Exception | |
log.puts $!.inspect | |
log.puts $!.backtrace | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment