git branch in my bash prompt 1

git branch in my bash prompt

parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "

Here is what the above code is Doing:
1. The first line is a function that will parse the git branch name.
2. The second line is the actual PS1 variable.
3. The \u is the username.
4. The \h is the hostname.
5. The \w is the current working directory.
6. The \033[32m is the color code for green.
7. The \033[33m is the color code for yellow.
8. The \033[00m is the color code for no color.
9. The \$(parse_git_branch) is the function that will parse the git branch name.
10. The $ is the prompt.

Similar Posts