# README
iTerm Command
This repo has a tool which does two things:
- Handle clicks from iterm
- Generate files which the iterm click-handler can understand
Installation
1. Install iterm-cmd
brew tap oliverisaac/tap
brew install oliverisaac/tap/iterm-cmd
2. Set up configuration
Edit your environment to configure how iterm-cmd
behaves. Configuration options are below.
3. Edit your iTerm2 Settings to use the click handling functionality:
- Get the path to the
iterm-cmd
command
which iterm-cmd
or you can generate the full command you'll need:
echo "${ITERM_CMD_DIR:+ITERM_CMD_DIR='${ITERM_CMD_DIR}' }'$( which iterm-cmd )' handle '\1' '\2'"
-
In iTerm2, go to the application preferences (
cmd
+comma
) -
Select Profiles -> Default -> Advanced
-
Under "Semantic History" select "Run Coprocess..."
-
In the text box that appears, paste in the path to the command and add:
handle '\1' '\2'
at the end. It should look something like:
/opt/homebrew/bin/iterm-cmd handle '\1' '\2'
- If you are using a custom
ITERM_CMD_DIR
then you will want to prefix the command with that definition. You will end up with something like
ITERM_CMD_DIR=/tmp/it2cmd /opt/homebrew/bin/iterm-cmd handle '\1' '\2'
4. Use the click handler
You can now use iterm-cmd
to generate a file which contains a command that iTerm2 can then execute. For example, run:
iterm-cmd echo "Hello world"
Then cmd-click
on the output filename.
Configuration
You will need to set these configuration items in the command to run
textbox of iTerm2's preferences.
ITERM_CMD_DIR
Sets where the files are created. This defaults to ${TMPDIR}/it2cmd
but can be set to any directory.
I would suggest setting ITERM_CMD_DIR=/tmp/it2cmd
ITERM_CMD_LS_AFTER_CD
The iterm-cmd click handler will, by default, execute an ls
after you click on a directory. Set this to false
to disable.
ITERM_CMD_PRINT_EASY_NAV
The iterm-cmd click handler will, by default, print out a click-map for you to quickly navigate. Something like:
< /path/to/previous/location ^ /path/to/parent/directory
Set this to false
to disable
ITERM_CMD_ENABLED
This is not a direct configuration option, but this is the environment variable you should use in a script to tell if a user would like to print out iterm-cmd paths. Something like this:
kubectl get pods -o name | while read podname; do
output="$podname"
if [[ ${ITERM_CMD_ENABLED:-false} == true ]]; then
output="$podname $( iterm-cmd kubectl get pod $podname -o yaml )"
fi
echo "$output"
done
ITERM_CMD_RUN_ON_CLICK
This will cause iterm-cmd to send a newline character after reading the command file. It does not guarantee that a command will not run. But helps it along if the command does not contain the trailing newline