iterm2-dwim
is a click handler for iTerm2:
you command-click on a file name in the iTerm2 terminal window, and it opens the file in your editor.
If there was a line number, your editor goes to that line.
So, compiler output, tracebacks, etc.
Currently, Emacs and Sublime are supported. To select an editor, enter "emacs" or "sublime" as the editor in "settings.py" and enter the path to emacsclient
or subl
.
The following path-like patterns are supported. For the ones with line numbers, the file will be opened at that line.
Pattern | Type | Status |
---|---|---|
/absolute/path/to/file |
Absolute path | |
relative/path/to/file |
Relative path | |
relative/path/to/file:336:1: |
Compiler / Linter etc output | |
a/relative/path/to/file |
In git diff output | |
"/absolute/path/to/file.py", line 336, in some_function |
Python stack traces | |
> /path/to/file.py(336)some_function() |
Python ipdb output |
Installation
-
Run
brew install terminal-notifier
and check it's working withterminal-notifier -message hello
. -
(Optional, but relative paths won't be resolved without it): configure your shell prompt so that the current directory is written to a file named
/tmp/cwd
every time the prompt is displayed. For example, put this line in your~/.bashrc
:export PROMPT_COMMAND='echo $PWD > /tmp/cwd'
-
Make sure that you are starting the emacs server in your emacs config file:
(require 'server) (unless (server-running-p) (server-start))
-
Clone this repo and run
python setup.py develop
. -
Find the absolute path to the
iterm2-dwim
executable, by running the commandwhich iterm2-dwim
. For example, on my system, this is/usr/local/bin/iterm2-dwim
. -
Open iTerm2 settings, click on "Profiles", select your profile, click on the "Advanced" tab for that profile, and do two things (see screenshots below):
- In the "Smart Selection" section, click "Edit", select the "Paths" rule, click "Edit Actions", click "+" to add an action, choose "Run Command" and enter
/absolute/path/to/iterm2-dwim \0 \d
as the "Parameter". - In the "Semantic History" section, choose "Run command" and enter
/absolute/path/to/iterm2-dwim \1 \4
. - Make sure you didn't literally enter
/absolute/path/to/
-- the path should be the path from step (5), given bywhich iterm2-dwim
.
- In the "Smart Selection" section, click "Edit", select the "Paths" rule, click "Edit Actions", click "+" to add an action, choose "Run Command" and enter
-
⌘-click on things!
Your iTerm2 settings should look something like this:
Debugging
This is under development and you will encounter problems initially. Probably, you'll command click on something and nothing will happen.
You can't use ipdb
to debug it: the python process is started by iTerm2 and is not attached to your terminal's standard input/output.
Similarly, note that the python process inherits its environment from the iTerm2 process and thus does not have access to environment modifications made in your shell config file.
It writes a log: run tail -f /tmp/iterm2-dwim.log
.
Problem | Fix |
---|---|
Command '['which', 'emacsclient']' returned non-zero exit status 1 |
Edit iterm2_dwim/editors/emacs.py so that it hard codes the absolute path to emacsclient on your system. |