|
56 | 56 | # setting the bash.showUpstream config variable.
|
57 | 57 | #
|
58 | 58 | # If you would like a colored hint about the current dirty state, set
|
59 |
| -# GIT_PS1_SHOWCOLORHINTS to a nonempty value. When tracked files are |
60 |
| -# modified, the branch name turns red, when all modifications are staged |
61 |
| -# the branch name turns yellow and when all changes are checked in, the |
62 |
| -# color changes to green. The colors are currently hardcoded in the function. |
63 |
| - |
| 59 | +# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on |
| 60 | +# the colored output of "git status -sb". |
| 61 | +# |
64 | 62 | # __gitdir accepts 0 or 1 arguments (i.e., location)
|
65 | 63 | # returns location of .git repo
|
66 | 64 | __gitdir ()
|
@@ -217,7 +215,7 @@ __git_ps1_show_upstream ()
|
217 | 215 | __git_ps1 ()
|
218 | 216 | {
|
219 | 217 | local pcmode=no
|
220 |
| - #defaults/examples: |
| 218 | + local detached=no |
221 | 219 | local ps1pc_start='\u@\h:\w '
|
222 | 220 | local ps1pc_end='\$ '
|
223 | 221 | local printf_format=' (%s)'
|
@@ -266,7 +264,7 @@ __git_ps1 ()
|
266 | 264 | fi
|
267 | 265 |
|
268 | 266 | b="$(git symbolic-ref HEAD 2>/dev/null)" || {
|
269 |
| - |
| 267 | + detached=yes |
270 | 268 | b="$(
|
271 | 269 | case "${GIT_PS1_DESCRIBE_STYLE-}" in
|
272 | 270 | (contains)
|
@@ -326,35 +324,46 @@ __git_ps1 ()
|
326 | 324 |
|
327 | 325 | local f="$w$i$s$u"
|
328 | 326 | if [ $pcmode = yes ]; then
|
329 |
| - PS1="$ps1pc_start(" |
330 |
| - if [ -n "${GIT_PS1_SHOWCOLORHINT-}" ]; then |
| 327 | + if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then |
331 | 328 | local c_red='\e[31m'
|
332 | 329 | local c_green='\e[32m'
|
333 |
| - local c_yellow='\e[33m' |
334 | 330 | local c_lblue='\e[1;34m'
|
335 |
| - local c_purple='\e[35m' |
336 |
| - local c_cyan='\e[36m' |
337 | 331 | local c_clear='\e[0m'
|
| 332 | + local bad_color=$c_red |
| 333 | + local ok_color=$c_green |
| 334 | + local branch_color="$c_clear" |
| 335 | + local flags_color="$c_lblue" |
338 | 336 | local branchstring="$c${b##refs/heads/}"
|
339 |
| - local branch_color="$c_green" |
340 |
| - local flags_color="$c_cyan" |
341 | 337 |
|
342 |
| - if [ "$w" = "*" ]; then |
343 |
| - branch_color="$c_red" |
344 |
| - elif [ -n "$i" ]; then |
345 |
| - branch_color="$c_yellow" |
| 338 | + if [ $detached = yes ]; then |
| 339 | + branch_color="$ok_color" |
| 340 | + else |
| 341 | + branch_color="$bad_color" |
346 | 342 | fi
|
347 | 343 |
|
348 | 344 | # Setting PS1 directly with \[ and \] around colors
|
349 | 345 | # is necessary to prevent wrapping issues!
|
350 |
| - PS1="$PS1\[$branch_color\]$branchstring\[$c_clear\]" |
351 |
| - if [ -n "$f" ]; then |
352 |
| - PS1="$PS1 \[$flags_color\]$f\[$c_clear\]" |
| 346 | + PS1="$ps1pc_start (\[$branch_color\]$branchstring\[$c_clear\]" |
| 347 | + |
| 348 | + if [ -n "$w$i$s$u$r$p" ]; then |
| 349 | + PS1="$PS1 " |
| 350 | + fi |
| 351 | + if [ "$w" = "*" ]; then |
| 352 | + PS1="$PS1\[$bad_color\]$w" |
| 353 | + fi |
| 354 | + if [ -n "$i" ]; then |
| 355 | + PS1="$PS1\[$ok_color\]$i" |
| 356 | + fi |
| 357 | + if [ -n "$s" ]; then |
| 358 | + PS1="$PS1\[$flags_color\]$s" |
| 359 | + fi |
| 360 | + if [ -n "$u" ]; then |
| 361 | + PS1="$PS1\[$bad_color\]$u" |
353 | 362 | fi
|
| 363 | + PS1="$PS1\[$c_clear\]$r$p)$ps1pc_end" |
354 | 364 | else
|
355 |
| - PS1="$PS1$c${b##refs/heads/}${f:+ $f}$r$p" |
| 365 | + PS1="$ps1pc_start ($c${b##refs/heads/}${f:+ $f}$r$p)$ps1pc_end" |
356 | 366 | fi
|
357 |
| - PS1="$PS1)$ps1pc_end" |
358 | 367 | else
|
359 | 368 | # NO color option unless in PROMPT_COMMAND mode
|
360 | 369 | printf -- "$printf_format" "$c${b##refs/heads/}${f:+ $f}$r$p"
|
|
0 commit comments