Skip to content

Commit

Permalink
Merge pull request #527 from knirch/fix-prompt
Browse files Browse the repository at this point in the history
Do not modify the first subscript of array PROMPT_COMMAND
  • Loading branch information
Rakotomandimby Mihamina authored May 19, 2023
2 parents 08a4af2 + a470aad commit c2f8ca6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions gitprompt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,25 @@ function add_to_end_of_prompt_command() {
}

function gp_install_prompt {
make_prompt_command_clean
add_to_end_of_prompt_command "setGitPrompt"
add_to_beginning_of_prompt_command "setLastCommandState"
# 5.1 supports PROMPT_COMMAND as an array
if ((BASH_VERSINFO[0] > 5 || BASH_VERSINFO[0] == 5 && BASH_VERSINFO[1] >= 1)); then
if [[ $(declare -p PROMPT_COMMAND 2>/dev/null) == "declare --"* ]]; then
make_prompt_command_clean
add_to_end_of_prompt_command "setGitPrompt"
add_to_beginning_of_prompt_command "setLastCommandState"
else
if [[ "${PROMPT_COMMAND[*]}" != *setGitPrompt* ]]; then
PROMPT_COMMAND+=(setGitPrompt)
fi
if [[ "${PROMPT_COMMAND[*]}" != *setLastCommandState* ]]; then
PROMPT_COMMAND=(setLastCommandState "${PROMPT_COMMAND[@]}")
fi
fi
else
make_prompt_command_clean
add_to_end_of_prompt_command "setGitPrompt"
add_to_beginning_of_prompt_command "setLastCommandState"
fi

set_git_prompt_dir
source "${__GIT_PROMPT_DIR}/git-prompt-help.sh"
Expand Down

0 comments on commit c2f8ca6

Please sign in to comment.