From 2fa7d136201bad92e8da6c38181cd2e58c654411 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 24 Aug 2021 23:19:55 -0500 Subject: Search multiple files for __git_ps1 function --- bash/prompt.bash | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'bash') diff --git a/bash/prompt.bash b/bash/prompt.bash index c61266b..df30c82 100644 --- a/bash/prompt.bash +++ b/bash/prompt.bash @@ -7,17 +7,29 @@ PROMPT_DIRTRIM=3 # how many dirs above current to print (rest are '...') PS1+='\[\e[36m\]\u@\h \w' # git bit -source /usr/share/git/git-prompt.sh && - PS1+='\[\e[35m\]$(__git_ps1)' +# see https://unix.stackexchange.com/questions/278206 +possible_git_prompt_locations=( + /usr/share/git/git-prompt.sh # Arch, etc. (default?) + /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ... + /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ?? +) + +for file in "${possible_git_prompt_locations[@]}"; do + if [[ -f "$file" ]]; then + source "$file" && + PS1+='\[\e[35m\]$(__git_ps1)' + break + fi +done # newline PS1+='\[\e[0m\]\n' # exit code (only if error) __prompt_exit_code() { - local ec=$? - (( $ec > 0 )) && - printf "$ec" + local ec=$? + (( $ec > 0 )) && + printf "$ec" } PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' -- cgit 1.4.1-21-gabe81