Skip to content

Instantly share code, notes, and snippets.

@aviddiviner
Last active June 8, 2016 16:56
Show Gist options
  • Save aviddiviner/c09217d2e8286561f4f193ccfab38b84 to your computer and use it in GitHub Desktop.
Save aviddiviner/c09217d2e8286561f4f193ccfab38b84 to your computer and use it in GitHub Desktop.
Smart hyperlinked stack traces in iTerm (open on correct line)
#!/usr/bin/python
import re
import sys
from subprocess import call
if len(sys.argv) > 2:
filename, linenum = sys.argv[1], sys.argv[2]
if re.search(r'\.(py|rb|go|js)$', filename) and linenum:
if not str.isdigit(linenum):
parts = linenum.split(',')
if len(parts) > 1:
linenum = filter(str.isdigit, parts[1])
if str.isdigit(linenum):
filename = '{0}:{1}'.format(filename, linenum)
call(['/usr/local/bin/subl', '--add', filename])
else:
call(['/usr/bin/open', filename])
# In iTerm, go to Profiles > Advanced > Semantic History > Run command...
# and set it to "/path/to/magic-iterm-open.py \1 \2 \4" (sans quotes)
# Also, make sure that Pointer > Cmd-Click Opens Filename/URL is enabled.
@rdrey
Copy link

rdrey commented Jun 8, 2016

👍

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