1+ # Returns 1 if git status for Cmder is disabled, otherwise returns 0
12function getGitStatusSetting() {
2- gitStatusSetting= $( git --no-pager config -l 2> /dev/null )
3+ local gitConfig
34
4- if [[ -n ${gitStatusSetting} ]] && [[ ${gitStatusSetting} =~ cmder.status= false ]] || [[ ${gitStatusSetting} =~ cmder.shstatus= false ]]
5+ # Get all git config entries for the current repository without pager
6+ gitConfig=$( git --no-pager config -l 2> /dev/null) || return 0 # treat failure as enabled
7+
8+ # Check if git status for Cmder is disabled
9+ if [[ $gitConfig =~ (^| $' \n ' )cmder\. status= false($| $' \n ' ) ]] || \
10+ [[ $gitConfig =~ (^| $' \n ' )cmder\. shstatus= false($| $' \n ' ) ]]
511 then
6- echo false
7- else
8- echo true
12+ return 1 # disabled
913 fi
14+
15+ return 0
1016}
1117
18+ # Prints current branch or detached HEAD short commit hash
1219function getSimpleGitBranch() {
13- gitDir=$( git rev-parse --git-dir 2> /dev/null)
14- if [ -z " $gitDir " ]; then
15- return 0
16- fi
20+ local gitDir
21+ gitDir=$( git rev-parse --git-dir 2> /dev/null) || return 0
22+
23+ local headFile=" $gitDir /HEAD"
24+ [ -f " $headFile " ] || return 0
1725
18- headContent=$( < " $gitDir /HEAD" )
19- if [[ " $headContent " == " ref: refs/heads/" * ]]
26+ local headContent
27+ headContent=$( < " $headFile " )
28+ if [[ " $headContent " =~ ^ref:\ refs/heads/(.+)$ ]]
2029 then
21- echo " (${headContent : 16 } )"
30+ echo " (${BASH_REMATCH[1] } )"
2231 else
2332 echo " (HEAD detached at ${headContent: 0: 7} )"
2433 fi
3342
3443if test -f ~ /.config/git/git-prompt.sh
3544then
36- if [[ $( getGitStatusSetting) == true ]]
45+ if getGitStatusSetting
3746 then
3847 . ~ /.config/git/git-prompt.sh
3948 fi
4049else
41- # Taken from https://github.com/git-for-windows/build-extra/blob/main/git-extra/git-prompt.sh
42- PS1=' \[\033]0;$TITLEPREFIX:$ {PWD//[^[:ascii:]]/?}\007\]' # set window title
50+ # Taken parts from https://github.com/git-for-windows/build-extra/blob/main/git-extra/git-prompt.sh
51+ PS1=' \[\033]0;${ TITLEPREFIX:+$TITLEPREFIX:}$ {PWD//[^[:ascii:]]/?}\007\]' # set window title to TITLEPREFIX (if set) and current working directory
4352 # PS1="$PS1"'\n' # new line (disabled)
44- PS1=" $PS1 " ' \[\033[32m\]' # change to green
53+ PS1=" $PS1 " ' \[\033[32m\]' # change to green and bold
4554 PS1=" $PS1 " ' \u@\h ' # user@host<space>
4655 PS1=" $PS1 ${MSYSTEM: +\[\0 33[35m\]$MSYSTEM } " # show MSYSTEM in purple (if set)
47- PS1=" $PS1 " ' \[\033[33m\]' # change to brownish yellow
56+ PS1=" $PS1 " ' \[\033[1; 33m\]' # change to dark yellow in bold
4857 PS1=" $PS1 " ' \w' # current working directory
4958 if test -z " $WINELOADERNOEXEC "
5059 then
5564 if test -f " $COMPLETION_PATH /git-prompt.sh"
5665 then
5766 . " $COMPLETION_PATH /git-completion.bash"
58- if [[ $( getGitStatusSetting) == true ]]
67+ if getGitStatusSetting
5968 then
6069 . " $COMPLETION_PATH /git-prompt.sh"
6170 PS1=" $PS1 " ' \[\033[36m\]' # change color to cyan
6675 fi
6776 fi
6877 fi
69- PS1=" $PS1 " ' \[\033[0m\]' # change color
78+ PS1=" $PS1 " ' \[\033[0m\]' # reset color
7079 PS1=" $PS1 " ' \n' # new line
80+ PS1=" $PS1 " ' \[\033[30;1m\]' # change color to grey in bold
7181 PS1=" $PS1 " ' λ ' # prompt: Cmder uses λ
82+ PS1=" $PS1 " ' \[\033[0m\]' # reset color
7283fi
7384
7485MSYS2_PS1=" $PS1 " # for detection by MSYS2 SDK's bash.basrc
8293 test ! -f " $c " ||
8394 . " $c "
8495 done
85- fi
96+ fi
0 commit comments