This repo has a tool which does two things:
- Handle clicks from iterm
- Generate files which the iterm click-handler can understand
brew tap oliverisaac/tap
brew install oliverisaac/tap/iterm-cmd
Edit your environment to configure how iterm-cmd
behaves. Configuration options are below.
- 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'
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.
You will need to set these configuration items in the command to run
textbox of iTerm2's preferences.
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
The iterm-cmd click handler will, by default, execute an ls
after you click on a directory. Set this to false
to disable.
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
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
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