diff options
Diffstat (limited to 'bash')
-rw-r--r-- | bash/prompt.bash | 22 |
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 '...') | |||
7 | PS1+='\[\e[36m\]\u@\h \w' | 7 | PS1+='\[\e[36m\]\u@\h \w' |
8 | 8 | ||
9 | # git bit | 9 | # git bit |
10 | source /usr/share/git/git-prompt.sh && | 10 | # see https://unix.stackexchange.com/questions/278206 |
11 | PS1+='\[\e[35m\]$(__git_ps1)' | 11 | possible_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 | |||
17 | for 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 | ||
23 | done | ||
12 | 24 | ||
13 | # newline | 25 | # newline |
14 | PS1+='\[\e[0m\]\n' | 26 | PS1+='\[\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 | } |
22 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' | 34 | PS1+='\[\e[31m\]$(__prompt_exit_code)\[\e[0m\]' |
23 | 35 | ||