Skip to content

Instantly share code, notes, and snippets.

@jturcotte
Created October 18, 2012 15:11
Show Gist options
  • Save jturcotte/3912465 to your computer and use it in GitHub Desktop.
Save jturcotte/3912465 to your computer and use it in GitHub Desktop.
Terminator plugin to open paths in Sublime Text
import re
import terminatorlib.plugin as plugin
import subprocess
# Every plugin you want Terminator to load *must* be listed in 'AVAILABLE'
AVAILABLE = ['FileURLHandler']
class FileURLHandler(plugin.URLHandler):
capabilities = ['url_handler']
handler_name = 'file_path'
# Match any non-space string starting with an alnum or a slash and ending with a line number
match = r'[a-zA-Z0-9\/][^ ]+:[[:digit:]]+|[a-zA-Z0-9\/][^ ]+\([[:digit:]]+\)'
def callback(self, url):
p = subprocess.Popen(["xclip", "-selection", "clipboard"], stdin=subprocess.PIPE)
p.communicate(input=url)
p.wait()
subprocess.call(["subl", "--command", "open_clipboard_path"])
return "some_random_string_just_so_that_opening_the_resulting_url_will_fail"
@nofxx
Copy link

nofxx commented Nov 24, 2014

@Wizek
Copy link

Wizek commented Dec 15, 2016

The callback can be simplified:

def callback(self, url):
    subprocess.call(["subl", url])
    return ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment