-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterm2_shell_integration.zsh
executable file
·68 lines (55 loc) · 2.03 KB
/
iterm2_shell_integration.zsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
if [[ -o login ]]; then
if [ x"$TERM" != "xscreen" ]; then
# Indicates start of command output. Runs just before command executes.
iterm2_before_cmd_executes() {
printf "\033]133;C\007"
}
iterm2_set_user_var() {
printf "\033]1337;SetUserVar=%s=%s\007" "$1" $(printf "%s" "$2" | base64)
}
# Users can write their own version of this method. It should call
# iterm2_set_user_var but not produce any other output.
# e.g., iterm2_set_user_var currentDirectory $PWD
# Accessible in iTerm2 (in a badge now, elsewhere in the future) as
# \(user.currentDirectory).
iterm2_print_user_vars() {
}
iterm2_print_state_data() {
printf "\033]1337;RemoteHost=$USER@$iterm2_hostname\007"
printf "\033]1337;CurrentDir=$PWD\007"
iterm2_print_user_vars
}
# Report return code of command; runs after command finishes but before prompt
iterm2_after_cmd_executes() {
printf "\033]133;D;$?\007"
iterm2_print_state_data
}
# Mark start of prompt
iterm2_prompt_start() {
printf "\033]133;A\007"
}
# Mark end of prompt
iterm2_prompt_end() {
printf "\033]133;B\007"
}
iterm2_precmd() {
iterm2_after_cmd_executes
# The user or another precmd may have changed PS1 (e.g., powerline-shell).
# Ensure that our escape sequences are added back in.
ITERM2_SAVED_PS1="$PS1"
PS1="%{$(iterm2_prompt_start)%}$ITERM2_SAVED_PS1%{$(iterm2_prompt_end)%}"
}
iterm2_preexec() {
PS1="$ITERM2_SAVED_PS1"
iterm2_before_cmd_executes
}
# If hostname -f is slow on your system, set iterm2_hostname prior to sourcing this script.
[[ -z "$iterm2_hostname" ]] && iterm2_hostname=`hostname -f`
[[ -z $precmd_functions ]] && precmd_functions=()
precmd_functions=($precmd_functions iterm2_precmd)
[[ -z $preexec_functions ]] && preexec_functions=()
preexec_functions=($preexec_functions iterm2_preexec)
iterm2_print_state_data
printf "\033]1337;ShellIntegrationVersion=1\007"
fi
fi