# Setup iTerm2 shell integration on macOS _setup_iterm2() { # Only run on macOS [ "$(uname -s 2>/dev/null)" = "Darwin" ] || return 0 # Only run if iTerm.app is available in /Applications or $HOME/Applications _iterm_app="" for _app_cand in \ "/Applications/iTerm.app" \ "$HOME/Applications/iTerm.app" \ "/Applications/ITerm.app" \ "$HOME/Applications/ITerm.app" \ "/Applications/iTerm2.app" \ "$HOME/Applications/iTerm2.app" do if [ -d "$_app_cand" ]; then _iterm_app="$_app_cand" break fi done [ -n "$_iterm_app" ] || return 0 # Add iTerm2 utilities (imgcat, it2dl, etc.) to PATH if available if [ -d "$_iterm_app/Contents/Resources/utilities" ]; then case ":$PATH:" in *":$_iterm_app/Contents/Resources/utilities:"*) ;; *) PATH="$_iterm_app/Contents/Resources/utilities:$PATH"; export PATH ;; esac fi # Only activate shell integration when running inside iTerm if [ "$TERM_PROGRAM" = "iTerm.app" ] || [ -n "$ITERM_SESSION_ID" ] || [ "$LC_TERMINAL" = "iTerm2" ]; then _shell_ext="" if [ -n "$ZSH_VERSION" ]; then _shell_ext="zsh" elif [ -n "$BASH_VERSION" ]; then _shell_ext="bash" elif [ -n "$FISH_VERSION" ]; then _shell_ext="fish" elif [ -n "$tcsh" ]; then _shell_ext="tcsh" fi if [ -n "$_shell_ext" ]; then _script_path="" if [ -r "$HOME/.iterm2_shell_integration.$_shell_ext" ]; then _script_path="$HOME/.iterm2_shell_integration.$_shell_ext" elif [ -r "$_iterm_app/Contents/Resources/iterm2_shell_integration.$_shell_ext" ]; then _script_path="$_iterm_app/Contents/Resources/iterm2_shell_integration.$_shell_ext" fi if [ -n "$_script_path" ]; then \. "$_script_path" fi fi fi } _setup_iterm2 unset -f _setup_iterm2