about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-08-24 23:19:55 -0500
committerCase Duckworth2021-08-24 23:19:55 -0500
commit2fa7d136201bad92e8da6c38181cd2e58c654411 (patch)
treea02d275af540cd8f5891f6796592f36847e4dd2f
parentEnsure GUIX_PROFILE/etc/profile is readable before sourcing (diff)
downloadetc-2fa7d136201bad92e8da6c38181cd2e58c654411.tar.gz
etc-2fa7d136201bad92e8da6c38181cd2e58c654411.zip
Search multiple files for __git_ps1 function
-rw-r--r--bash/prompt.bash22
1 files changed, 17 insertions, 5 deletions
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 '...')
7PS1+='\[\e[36m\]\u@\h \w' 7PS1+='\[\e[36m\]\u@\h \w'
8 8
9# git bit 9# git bit
10source /usr/share/git/git-prompt.sh && 10# see https://unix.stackexchange.com/questions/278206
11 PS1+='\[\e[35m\]$(__git_ps1)' 11possible_git_prompt_locations=(
12 /usr/share/git/git-prompt.sh # Arch, etc. (default?)
13 /usr/lib/git-core/git-sh-prompt # Debian, Ubuntu ...
14 /usr/share/git-core/contrib/completion/git-prompt.sh # Fedora ??
15)
16
17for file in "${possible_git_prompt_locations[@]}"; do
18 if [[ -f "$file" ]]; then
19 source "$file" &&
20 PS1+='\[\e[35m\]$(__git_ps1)'
21 break
22 fi
23done
12 24
13# newline 25# newline
14PS1+='\[\e[0m\]\n' 26PS1+='\[\e[0m\]\n'
15 27
16# exit code (only if error) 28# exit code (only if error)
17__prompt_exit_code() { 29__prompt_exit_code() {
18 local ec=$? 30 local ec=$?
19 (( $ec > 0 )) && 31 (( $ec > 0 )) &&
20 printf "$ec" 32 printf "$ec"
21} 33}
22PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' 34PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]'
23 35