terminal: open editor by click on stacktrace line
Question: I want python stacktrace lines to act like hyperlinks in a terminal. My
favorite editor should open the file and go to the correct line:

    
    
    Traceback (most recent call last):
      File "/home/foo_eins_dt/djangotools/utils/smtputils.py", line 73, in _inner_to_outbox
        return func(*args, **kwargs)
      File "/home/foo_eins_dt/foo_mail/tests/EditTest.py", line 289, in test_something
        beleg_ids=importutils.import_msg_file(temp)
    TypeError: bar() takes exactly 2 arguments (1 given)
    

Up to now I use gnome-terminal, but I could switch to a different terminal.

Example: I want to click on `File
"/home/foo_eins_dt/foo_mail/tests/EditTest.py"` and the file EditTest.py
should be opened at line 289.


Answer: For the internet future: This is possible in OS X in [iTerm
2](https://iterm2.com/index.html)

Here is my setup with Sublime Text: `~/bin/magic-iterm-open.py`

    
    
    #!/usr/bin/python
    
    import sys
    from subprocess import call
    
    if len(sys.argv) > 2:
    
        pathToSubl = "/Users/rainer/bin/"
    
        filename, linenum = sys.argv[1], sys.argv[2]
        rest = "" if len(sys.argv) < 4 else sys.argv[3]
    
        if not filename.endswith('.py'):
            # I believe this approximates iTerm's default
            call(['/usr/bin/open', filename])
        else:
            newLinenum = linenum
            if not str.isdigit(linenum):
                line = linenum.split(",")
                if len(line) > 1:
                    newLinenum = filter(str.isdigit, line[1])
    
            command = ["{0}subl".format(pathToSubl),
                       "--add",  # If you'd like to add to your current sublime project
                       "{0}:{1}".format(filename, newLinenum)]
    
            call(command)
    

And the config in iTerm2:

[![enter image description
here](http://i.stack.imgur.com/Ymso8.gif)](http://i.stack.imgur.com/Ymso8.gif)

All credit goes to an old redit post, here:
<https://www.reddit.com/r/SublimeText/comments/1kanze/iterm2_jump_to_location_in_sublime_text_23/>

