2023-12-05 12:34:53 -08:00
|
|
|
if [ -r ~/.bashrc ]; then
|
|
|
|
|
. ~/.bashrc
|
|
|
|
|
fi
|
|
|
|
|
if [ -r /etc/profile ]; then
|
|
|
|
|
. /etc/profile
|
|
|
|
|
fi
|
|
|
|
|
if [ -r ~/.bash_profile ]; then
|
|
|
|
|
. ~/.bash_profile
|
|
|
|
|
elif [ -r ~/.bash_login ]; then
|
|
|
|
|
. ~/.bash_login
|
|
|
|
|
elif [ -r ~/.profile ]; then
|
|
|
|
|
. ~/.profile
|
|
|
|
|
fi
|
|
|
|
|
|
2023-12-14 14:53:12 -08:00
|
|
|
if [ -r ~/.inshellisense/bash-preexec.sh ]; then
|
|
|
|
|
. ~/.inshellisense/bash-preexec.sh
|
|
|
|
|
fi
|
|
|
|
|
|
2023-12-05 12:24:48 -08:00
|
|
|
__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() {
|
|
|
|
|
# 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 printf '%s\n' "${out}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__is_update_cwd() {
|
|
|
|
|
builtin printf '\e]6973;CWD;%s\a' "$(__is_escape_value "$PWD")"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if [[ -n "${bash_preexec_imported:-}" ]]; then
|
2024-03-09 14:58:12 -08:00
|
|
|
precmd_functions+=(__is_precmd)
|
2023-12-14 14:53:12 -08:00
|
|
|
fi
|
|
|
|
|
|
2024-03-09 14:58:12 -08:00
|
|
|
__is_precmd() {
|
|
|
|
|
__is_update_cwd
|
|
|
|
|
__is_update_prompt
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 12:24:48 -08:00
|
|
|
__is_update_prompt() {
|
|
|
|
|
if [[ "$__is_custom_PS1" == "" || "$__is_custom_PS1" != "$PS1" ]]; then
|
|
|
|
|
__is_original_PS1=$PS1
|
2024-02-15 15:13:32 -05:00
|
|
|
if [ $ISTERM_TESTING == "1" ]; then
|
|
|
|
|
__is_original_PS1="> "
|
|
|
|
|
fi
|
2023-12-05 12:24:48 -08:00
|
|
|
__is_custom_PS1="\[$(__is_prompt_start)\]$__is_original_PS1\[$(__is_prompt_end)\]"
|
2024-03-09 22:15:45 -08:00
|
|
|
PS1="$__is_custom_PS1"
|
2023-12-05 12:24:48 -08:00
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-09 14:58:12 -08:00
|
|
|
__is_prompt_cmd_original() {
|
|
|
|
|
for cmd in "${__is_original_prompt_command[@]}"; do
|
|
|
|
|
eval "${cmd:-}"
|
|
|
|
|
done
|
|
|
|
|
__is_precmd
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-09 22:15:45 -08:00
|
|
|
# handles when a user's PROMPT_COMMAND resets their prompt after the precmd hook is triggered
|
|
|
|
|
__is_prompt_cmd_safe() {
|
|
|
|
|
for cmd in "${__is_original_prompt_command[@]}"; do
|
|
|
|
|
eval "${cmd:-}"
|
|
|
|
|
done
|
|
|
|
|
if [[ "$PS1" != "$__is_safe_PS1" ]]; then
|
|
|
|
|
__is_precmd
|
|
|
|
|
__is_safe_PS1="$PS1"
|
|
|
|
|
fi
|
|
|
|
|
}
|
2024-03-09 14:58:12 -08:00
|
|
|
|
|
|
|
|
__is_original_prompt_command=${PROMPT_COMMAND:-}
|
|
|
|
|
if [[ -z "${bash_preexec_imported:-}" ]]; then
|
|
|
|
|
if [[ -n "${__is_original_prompt_command:-}" && "${__is_original_prompt_command:-}" != "__is_precmd" ]]; then
|
|
|
|
|
PROMPT_COMMAND=__is_prompt_cmd_original
|
|
|
|
|
else
|
|
|
|
|
PROMPT_COMMAND=__is_precmd
|
|
|
|
|
fi
|
2024-03-09 22:15:45 -08:00
|
|
|
else
|
|
|
|
|
if [[ -n "${__is_original_prompt_command:-}" && "${__is_original_prompt_command:-}" != "__is_precmd" ]]; then
|
|
|
|
|
PROMPT_COMMAND=__is_prompt_cmd_safe
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
__is_precmd
|