]> arthur.barton.de Git - ax-zsh.git/blobdiff - plugins/iterm2/iterm2.zshrc
iterm2: Add iTerm 2 tools folder to search path
[ax-zsh.git] / plugins / iterm2 / iterm2.zshrc
index 3e245ca2ce246180c09ecc8b341165e8993809f7..458ca688f80e12a1645145ef68e1628acab93176 100644 (file)
@@ -4,10 +4,18 @@
 [[ -z "$AXZSH_PLUGIN_CHECK" ]] || return 92
 
 # Check prerequisites ...
-axzsh_is_dumb_terminal && return 91
+axzsh_is_modern_terminal || return 91
 [[ -o interactive ]] || return 91
 [[ -z "$ITERM_SHELL_INTEGRATION_INSTALLED" ]] || return 91
-[[ "$TERM" != "screen" && "$TERM" != "screen-256color" ]] || return 91
+[[ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}$TERM" =~ "^screen" ]] && return 91
+
+# Add iTerm2 commands to PATH, when available.
+[[ -d ~/.iterm2 ]] && path+=(~/.iterm2)
+
+# Try to source user-local shell integration installed by iTerm2 itself,
+# and only fall back to the implementation here when not found.
+[[ -e "$HOME/.iterm2_shell_integration.zsh" ]] && source "$HOME/.iterm2_shell_integration.zsh"
+[[ -z "$ITERM_SHELL_INTEGRATION_INSTALLED" ]] || return 0
 
 ITERM_SHELL_INTEGRATION_INSTALLED="Yes"
 ITERM2_SHOULD_DECORATE_PROMPT="1"
@@ -27,7 +35,7 @@ iterm2_set_user_var() {
 # Accessible in iTerm2 (in a badge now, elsewhere in the future) as
 # \(user.currentDirectory).
 whence -v iterm2_print_user_vars > /dev/null 2>&1
-if [[ $? -ne 0 ]]; then
+if [ $? -ne 0 ]; then
        iterm2_print_user_vars() {
                :
        }
@@ -100,17 +108,22 @@ iterm2_decorate_prompt() {
        ITERM2_SHOULD_DECORATE_PROMPT=""
 
        # Add our escape sequences just before the prompt is shown.
-       if [[ $PS1 == *'$(iterm2_prompt_mark)'* ]]
-       then
-               PS1="$PS1%{$(iterm2_prompt_end)%}"
+       # Use ITERM2_SQUELCH_MARK for people who can't mdoify PS1 directly, like powerlevel9k users.
+       # This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2.
+       local PREFIX=""
+       if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then
+               PREFIX=""
+       elif [[ "${ITERM2_SQUELCH_MARK-}" != "" ]]; then
+               PREFIX=""
        else
-               PS1="%{$(iterm2_prompt_mark)%}$PS1%{$(iterm2_prompt_end)%}"
+               PREFIX="%{$(iterm2_prompt_mark)%}"
        fi
+       PS1="$PREFIX$PS1%{$(iterm2_prompt_end)%}"
 }
 
 iterm2_precmd() {
        local STATUS="$?"
-       if [ -z "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then
+       if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then
                # You pressed ^C while entering a command (iterm2_preexec did not run)
                iterm2_before_cmd_executes
        fi
@@ -137,10 +150,10 @@ precmd_functions+=(iterm2_precmd)
 preexec_functions+=(iterm2_preexec)
 
 iterm2_print_state_data
-printf "\033]1337;ShellIntegrationVersion=5;shell=zsh\007"
+printf "\033]1337;ShellIntegrationVersion=11;shell=zsh\007"
 
 # Setup iTerm2 command aliases
-for cmd (~/.iterm2/*); do
+for cmd (~/.iterm2/*(N)); do
        [[ -x "$cmd" ]] && alias "$(basename "$cmd")=$cmd"
 done
 unset cmd