I have a color schema for my XFCE terminal
and I try to set the branch name and color when I'm inside a directory which is a Git Repository
.
Actually this is the configuration of my bash:
PS1="\u@\h $(if [[ ${EUID} == 0 ]]; then echo '\W'; else echo '\w'; fi) \$([[ \$? != 0 ]] && echo \":( \")\$ "
and when I'm inside a directory which is a Git Repository I want to show that:
[\u@\h \W]\[\033[00;32m\]\$(git_branch)\[\033[00m\]\$
this is the git_branch function
:
git_branch() { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' }
I tried to edit the PS1
as that:
\$(if [[git rev-parse --is-inside-work-tree]]; then [\u@\h \W]\[\033[00;32m\]\$(git_branch)\[\033[00m\]\$
but it isn't working - when I'm inside the directory of Git repository, it doesn't show me the name of the branch.
Thank you very much!