The goal is to display the status of a git repository directly in the prompt.
- Update the
.bashrc
file with the following lines
export GIT_PS1_SHOWDIRTYSTATE=1
export GIT_PS1_SHOWUNTRACKEDFILES=1
export GIT_PS1_SHOWUPSTREAM="auto verbose"
export GIT_PS1_SHOWCOLORHINTS=1
export GIT_PS1_SHOWSTASHSTATE=1
export PROMPT_COMMAND='__git_ps1 "\[\033[33m\]\w\[\033[0m\]" "\n\\\$ "'
This solution displays many information but is slow (adding some seconds for displaying the prompt)
- Update the
.bashrc
file with the following lines
git_color() {
[[ -n $(git status --porcelain=v2 2>/dev/null) ]] && echo 31 || echo 32
}
export PS1='\[\033[33m\]\w\[\033[`git_color`m\]`__git_ps1`\[\033[0m\]\n$ '
This solution keeps unchanged the information displayed, but changes the color (green
if status is clean, otherwise red
)