-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathshellIntegration-rc.zsh
More file actions
72 lines (59 loc) · 1.34 KB
/
shellIntegration-rc.zsh
File metadata and controls
72 lines (59 loc) · 1.34 KB
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
69
70
71
72
autoload -U add-zsh-hook
if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
ZDOTDIR=$USER_ZDOTDIR
. $USER_ZDOTDIR/.zshrc
fi
__is_prompt_start() {
builtin printf '\e]6973;PS\a' > /dev/tty
}
__is_prompt_end() {
builtin printf '\e]6973;PE\a' > /dev/tty
}
__is_escape_value() {
builtin emulate -L zsh
# Process text byte by byte, not by codepoint.
builtin local LC_ALL=C str="$1" i byte token out=''
for (( i = 0; i < ${#str}; ++i )); do
byte="${str:$i:1}"
# Escape backslashes and semi-colons
if [ "$byte" = "\\" ]; then
token="\\\\"
elif [ "$byte" = ";" ]; then
token="\\x3b"
elif [ "$byte" = $'\n' ]; then
token="\x0a"
elif [ "$byte" = $'\e' ]; then
token="\\x1b"
elif [ "$byte" = $'\a' ]; then
token="\\x07"
else
token="$byte"
fi
out+="$token"
done
builtin print -r "$out"
}
__is_update_cwd() {
builtin printf '\e]6973;CWD;%s\a' "$(__is_escape_value "${PWD}")"
}
__is_precmd() {
__is_update_cwd
if [[ $ISTERM_TESTING == "1" ]]; then
PS1="%{$(__is_prompt_start)%}> %{$(__is_prompt_end)%}"
fi
}
if (( ${+widgets[zle-line-init]} )); then
zle -A zle-line-init __is_orig_zle_line_init
__is_zle_line_init() {
__is_prompt_start
zle __is_orig_zle_line_init
__is_prompt_end
}
else
__is_zle_line_init() {
__is_prompt_start
__is_prompt_end
}
fi
zle -N zle-line-init __is_zle_line_init
add-zsh-hook precmd __is_precmd