annotate .shell.d/99.iterm2_integration.zsh @ 526:852565046ed0 default tip

zsh: fidget with screen/tmux message This should speed things up very slightly by avoiding some `grep` action in the common case of no detached screens/tmuxes.
author Augie Fackler <raf@durin42.com>
date Mon, 14 Nov 2022 11:02:35 -0500
parents 9af1fc9b713c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
520
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1 # This program is free software; you can redistribute it and/or
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2 # modify it under the terms of the GNU General Public License
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 # as published by the Free Software Foundation; either version 2
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 # of the License, or (at your option) any later version.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 #
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6 # This program is distributed in the hope that it will be useful,
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 # GNU General Public License for more details.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 #
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 # You should have received a copy of the GNU General Public License
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12 # along with this program; if not, write to the Free Software
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15 if [[ -o interactive ]]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 if [ "${ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX-}""$TERM" != "screen" -a "${ITERM_SHELL_INTEGRATION_INSTALLED-}" = "" -a "$TERM" != linux -a "$TERM" != dumb ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 ITERM_SHELL_INTEGRATION_INSTALLED=Yes
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 ITERM2_SHOULD_DECORATE_PROMPT="1"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 # Indicates start of command output. Runs just before command executes.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 iterm2_before_cmd_executes() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 if [ "$TERM_PROGRAM" = "iTerm.app" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 printf "\033]133;C;\r\007"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 else
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 printf "\033]133;C;\007"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
25 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
26 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
27
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
28 iterm2_set_user_var() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
29 printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64 | tr -d '\n')
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
30 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
31
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
32 # Users can write their own version of this method. It should call
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
33 # iterm2_set_user_var but not produce any other output.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
34 # e.g., iterm2_set_user_var currentDirectory $PWD
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
35 # Accessible in iTerm2 (in a badge now, elsewhere in the future) as
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
36 # \(user.currentDirectory).
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
37 whence -v iterm2_print_user_vars > /dev/null 2>&1
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
38 if [ $? -ne 0 ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
39 iterm2_print_user_vars() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
40 true
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
41 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
42 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
43
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
44 iterm2_print_state_data() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
45 local _iterm2_hostname="${iterm2_hostname-}"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
46 if [ -z "${iterm2_hostname:-}" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
47 _iterm2_hostname=$(hostname -f 2>/dev/null)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
48 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
49 printf "\033]1337;RemoteHost=%s@%s\007" "$USER" "${_iterm2_hostname-}"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
50 printf "\033]1337;CurrentDir=%s\007" "$PWD"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
51 iterm2_print_user_vars
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
52 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
53
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
54 # Report return code of command; runs after command finishes but before prompt
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
55 iterm2_after_cmd_executes() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
56 printf "\033]133;D;%s\007" "$STATUS"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
57 iterm2_print_state_data
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
58 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
59
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
60 # Mark start of prompt
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
61 iterm2_prompt_mark() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
62 printf "\033]133;A\007"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
63 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
64
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
65 # Mark end of prompt
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
66 iterm2_prompt_end() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
67 printf "\033]133;B\007"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
68 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
69
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
70 # There are three possible paths in life.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
71 #
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
72 # 1) A command is entered at the prompt and you press return.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
73 # The following steps happen:
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
74 # * iterm2_preexec is invoked
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
75 # * PS1 is set to ITERM2_PRECMD_PS1
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
76 # * ITERM2_SHOULD_DECORATE_PROMPT is set to 1
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
77 # * The command executes (possibly reading or modifying PS1)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
78 # * iterm2_precmd is invoked
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
79 # * ITERM2_PRECMD_PS1 is set to PS1 (as modified by command execution)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
80 # * PS1 gets our escape sequences added to it
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
81 # * zsh displays your prompt
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
82 # * You start entering a command
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
83 #
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
84 # 2) You press ^C while entering a command at the prompt.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
85 # The following steps happen:
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
86 # * (iterm2_preexec is NOT invoked)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
87 # * iterm2_precmd is invoked
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
88 # * iterm2_before_cmd_executes is called since we detected that iterm2_preexec was not run
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
89 # * (ITERM2_PRECMD_PS1 and PS1 are not messed with, since PS1 already has our escape
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
90 # sequences and ITERM2_PRECMD_PS1 already has PS1's original value)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
91 # * zsh displays your prompt
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
92 # * You start entering a command
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
93 #
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
94 # 3) A new shell is born.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
95 # * PS1 has some initial value, either zsh's default or a value set before this script is sourced.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
96 # * iterm2_precmd is invoked
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
97 # * ITERM2_SHOULD_DECORATE_PROMPT is initialized to 1
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
98 # * ITERM2_PRECMD_PS1 is set to the initial value of PS1
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
99 # * PS1 gets our escape sequences added to it
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
100 # * Your prompt is shown and you may begin entering a command.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
101 #
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
102 # Invariants:
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
103 # * ITERM2_SHOULD_DECORATE_PROMPT is 1 during and just after command execution, and "" while the prompt is
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
104 # shown and until you enter a command and press return.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
105 # * PS1 does not have our escape sequences during command execution
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
106 # * After the command executes but before a new one begins, PS1 has escape sequences and
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
107 # ITERM2_PRECMD_PS1 has PS1's original value.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
108 iterm2_decorate_prompt() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
109 # This should be a raw PS1 without iTerm2's stuff. It could be changed during command
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
110 # execution.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
111 ITERM2_PRECMD_PS1="$PS1"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
112 ITERM2_SHOULD_DECORATE_PROMPT=""
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
113
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
114 # Add our escape sequences just before the prompt is shown.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
115 # Use ITERM2_SQUELCH_MARK for people who can't mdoify PS1 directly, like powerlevel9k users.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
116 # This is gross but I had a heck of a time writing a correct if statetment for zsh 5.0.2.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
117 local PREFIX=""
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
118 if [[ $PS1 == *"$(iterm2_prompt_mark)"* ]]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
119 PREFIX=""
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
120 elif [[ "${ITERM2_SQUELCH_MARK-}" != "" ]]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
121 PREFIX=""
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
122 else
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
123 PREFIX="%{$(iterm2_prompt_mark)%}"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
124 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
125 PS1="$PREFIX$PS1%{$(iterm2_prompt_end)%}"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
126 ITERM2_DECORATED_PS1="$PS1"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
127 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
128
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
129 iterm2_precmd() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
130 local STATUS="$?"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
131 if [ -z "${ITERM2_SHOULD_DECORATE_PROMPT-}" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
132 # You pressed ^C while entering a command (iterm2_preexec did not run)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
133 iterm2_before_cmd_executes
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
134 if [ "$PS1" != "${ITERM2_DECORATED_PS1-}" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
135 # PS1 changed, perhaps in another precmd. See issue 9938.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
136 ITERM2_SHOULD_DECORATE_PROMPT="1"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
137 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
138 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
139
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
140 iterm2_after_cmd_executes "$STATUS"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
141
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
142 if [ -n "$ITERM2_SHOULD_DECORATE_PROMPT" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
143 iterm2_decorate_prompt
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
144 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
145 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
146
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
147 # This is not run if you press ^C while entering a command.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
148 iterm2_preexec() {
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
149 # Set PS1 back to its raw value prior to executing the command.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
150 PS1="$ITERM2_PRECMD_PS1"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
151 ITERM2_SHOULD_DECORATE_PROMPT="1"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
152 iterm2_before_cmd_executes
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
153 }
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
154
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
155 # If hostname -f is slow on your system set iterm2_hostname prior to
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
156 # sourcing this script. We know it is fast on macOS so we don't cache
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
157 # it. That lets us handle the hostname changing like when you attach
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
158 # to a VPN.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
159 if [ -z "${iterm2_hostname-}" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
160 if [ "$(uname)" != "Darwin" ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
161 iterm2_hostname=`hostname -f 2>/dev/null`
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
162 # Some flavors of BSD (i.e. NetBSD and OpenBSD) don't have the -f option.
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
163 if [ $? -ne 0 ]; then
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
164 iterm2_hostname=`hostname`
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
165 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
166 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
167 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
168
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
169 [[ -z ${precmd_functions-} ]] && precmd_functions=()
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
170 precmd_functions=($precmd_functions iterm2_precmd)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
171
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
172 [[ -z ${preexec_functions-} ]] && preexec_functions=()
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
173 preexec_functions=($preexec_functions iterm2_preexec)
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
174
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
175 iterm2_print_state_data
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
176 printf "\033]1337;ShellIntegrationVersion=13;shell=zsh\007"
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
177 fi
9af1fc9b713c zsh: enable iterm2 integration
Augie Fackler <raf@durin42.com>
parents:
diff changeset
178 fi