From 9e7bef8e42eb36c7aaeb8a8f34175ac4202c2ad8 Mon Sep 17 00:00:00 2001 From: Chapman Pendery <35637443+cpendery@users.noreply.github.com> Date: Sat, 9 Mar 2024 22:15:45 -0800 Subject: [PATCH] fix: PROMPT_COMMAND overriding precmd hook results for oh-my-bash (#203) Signed-off-by: Chapman Pendery --- shell/shellIntegration.bash | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/shell/shellIntegration.bash b/shell/shellIntegration.bash index f86a97c..c0a5d7d 100644 --- a/shell/shellIntegration.bash +++ b/shell/shellIntegration.bash @@ -66,7 +66,7 @@ __is_update_prompt() { __is_original_PS1="> " fi __is_custom_PS1="\[$(__is_prompt_start)\]$__is_original_PS1\[$(__is_prompt_end)\]" - export PS1="$__is_custom_PS1" + PS1="$__is_custom_PS1" fi } @@ -77,6 +77,16 @@ __is_prompt_cmd_original() { __is_precmd } +# 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 +} __is_original_prompt_command=${PROMPT_COMMAND:-} if [[ -z "${bash_preexec_imported:-}" ]]; then @@ -85,4 +95,10 @@ if [[ -z "${bash_preexec_imported:-}" ]]; then else PROMPT_COMMAND=__is_precmd fi -fi \ No newline at end of file +else + if [[ -n "${__is_original_prompt_command:-}" && "${__is_original_prompt_command:-}" != "__is_precmd" ]]; then + PROMPT_COMMAND=__is_prompt_cmd_safe + fi +fi + +__is_precmd \ No newline at end of file