|
1 | 1 | function getGitStatusSetting() { |
2 | | - gitStatusSetting=$(git --no-pager config -l 2>/dev/null) |
| 2 | + local gitConfig |
3 | 3 |
|
4 | | - if [[ -n ${gitStatusSetting} ]] && [[ ${gitStatusSetting} =~ cmder.status=false ]] || [[ ${gitStatusSetting} =~ cmder.shstatus=false ]] |
| 4 | + # Get all git config entries for the current repository without pager |
| 5 | + gitConfig=$(git --no-pager config -l 2>/dev/null) || return 0 # treat failure as enabled |
| 6 | + |
| 7 | + # Check if git status for Cmder is disabled |
| 8 | + if [[ $gitConfig =~ (^|$'\n')cmder\.status=false($|$'\n') ]] || \ |
| 9 | + [[ $gitConfig =~ (^|$'\n')cmder\.shstatus=false($|$'\n') ]] |
5 | 10 | then |
6 | | - echo false |
7 | | - else |
8 | | - echo true |
| 11 | + return 1 # disabled |
9 | 12 | fi |
| 13 | + |
| 14 | + return 0 |
10 | 15 | } |
11 | 16 |
|
| 17 | +# Prints current branch or detached HEAD short commit hash |
12 | 18 | function getSimpleGitBranch() { |
13 | | - gitDir=$(git rev-parse --git-dir 2>/dev/null) |
14 | | - if [ -z "$gitDir" ]; then |
15 | | - return 0 |
16 | | - fi |
| 19 | + local gitDir |
| 20 | + gitDir=$(git rev-parse --git-dir 2>/dev/null) || return 0 |
| 21 | + |
| 22 | + local headFile="$gitDir/HEAD" |
| 23 | + [ -f "$headFile" ] || return 0 |
17 | 24 |
|
18 | | - headContent=$(< "$gitDir/HEAD") |
19 | | - if [[ "$headContent" == "ref: refs/heads/"* ]] |
| 25 | + local headContent |
| 26 | + headContent=$(< "$headFile") |
| 27 | + if [[ "$headContent" =~ ^ref:\ refs/heads/(.+)$ ]] |
20 | 28 | then |
21 | | - echo " (${headContent:16})" |
| 29 | + echo " (${BASH_REMATCH[1]})" |
22 | 30 | else |
23 | 31 | echo " (HEAD detached at ${headContent:0:7})" |
24 | 32 | fi |
|
33 | 41 |
|
34 | 42 | if test -f ~/.config/git/git-prompt.sh |
35 | 43 | then |
36 | | - if [[ $(getGitStatusSetting) == true ]] |
| 44 | + if getGitStatusSetting |
37 | 45 | then |
38 | 46 | . ~/.config/git/git-prompt.sh |
39 | 47 | fi |
|
55 | 63 | if test -f "$COMPLETION_PATH/git-prompt.sh" |
56 | 64 | then |
57 | 65 | . "$COMPLETION_PATH/git-completion.bash" |
58 | | - if [[ $(getGitStatusSetting) == true ]] |
| 66 | + if getGitStatusSetting |
59 | 67 | then |
60 | 68 | . "$COMPLETION_PATH/git-prompt.sh" |
61 | 69 | PS1="$PS1"'\[\033[36m\]' # change color to cyan |
|
0 commit comments