Skip to content

Instantly share code, notes, and snippets.

@nsfmc
Created March 28, 2012 17:48
Show Gist options
  • Save nsfmc/2228667 to your computer and use it in GitHub Desktop.
Save nsfmc/2228667 to your computer and use it in GitHub Desktop.
link to kiln textmate command
#!/usr/bin/env python
#
# beforeRunningCommand: nop
# input: selection
# inputFormat: text
# keyEquivalent: ^@k
# name: link to kiln
# outputCaret: afterOutput
# outputFormat: text
# outputLocation: toolTip
# uuid: BBCD2F4A-07A7-4DEF-B002-667D9C3DF714
# version: 2
#
import os
from sys import stdout, stdin
import subprocess
hg = os.getenv('TM_HG', 'hg')
os.chdir(os.getenv('TM_DIRECTORY'))
def popen_results(args):
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
return proc.communicate()[0]
default_path = popen_results([hg, 'paths', 'default']).strip()
repo_root = popen_results([hg, 'root']).strip()
file_path = os.getenv('TM_FILEPATH')
relpath = file_path.split(repo_root)[1]
lines = [x.split(":")[0] for x in os.getenv('TM_SELECTION').split("-")]
selection = "-".join(lines)
kiln_url = default_path + "/File"+ relpath + "#" + selection
print kiln_url
out = os.popen('/usr/bin/pbcopy', 'w')
out.write(kiln_url)
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment