Show git branch name in terminal prompt

suggest change

You can have functions in the PS1 variable, just make sure to single quote it or use escape for special chars:

gitPS1(){
    gitps1=$(git branch 2>/dev/null | grep '*')
    gitps1="${gitps1:+ (${gitps1/#\* /})}"
    echo "$gitps1"
}

PS1='\u@\h:\w$(gitPS1)$ '

It will give you a prompt like this:

user@Host:/path (master)$

Notes:

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents