2023-12-05 12:24:48 -08:00
|
|
|
if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
|
|
|
|
|
ZDOTDIR=$USER_ZDOTDIR
|
|
|
|
|
. $USER_ZDOTDIR/.zshrc
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
__is_prompt_start() {
|
|
|
|
|
builtin printf '\e]6973;PS\a'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__is_prompt_end() {
|
|
|
|
|
builtin printf '\e]6973;PE\a'
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-14 14:53:12 -08:00
|
|
|
__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"
|
|
|
|
|
else
|
|
|
|
|
token="$byte"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
out+="$token"
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
builtin print -r "$out"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__is_update_cwd() {
|
2023-12-22 13:56:06 -05:00
|
|
|
builtin printf '\e]6973;CWD;%s\a' "$(__is_escape_value "${PWD}")"
|
2023-12-14 14:53:12 -08:00
|
|
|
}
|
|
|
|
|
|
2023-12-05 12:24:48 -08:00
|
|
|
__is_update_prompt() {
|
|
|
|
|
__is_prior_prompt="$PS1"
|
2024-03-06 01:31:27 -05:00
|
|
|
if [[ $ISTERM_TESTING == "1" ]]; then
|
|
|
|
|
__is_prior_prompt="> "
|
2024-02-15 15:13:32 -05:00
|
|
|
fi
|
2024-03-06 13:10:51 -05:00
|
|
|
PS1="%{$(__is_prompt_start)%}$__is_prior_prompt%{$(__is_prompt_end)%}"
|
2023-12-05 12:24:48 -08:00
|
|
|
}
|
|
|
|
|
|
2023-12-14 14:53:12 -08:00
|
|
|
__is_precmd() {
|
2024-03-06 14:09:16 -05:00
|
|
|
if [[ $PS1 != *"$(__is_prompt_start)"* ]]; then
|
|
|
|
|
__is_update_prompt
|
|
|
|
|
fi
|
2023-12-14 14:53:12 -08:00
|
|
|
__is_update_cwd
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__is_update_prompt
|
|
|
|
|
add-zsh-hook precmd __is_precmd
|