I have a function defined in my user's .bashrc file that displays my current git branch name at my command prompt:
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
PS1="\\[$(tput setaf 7)\\]\\w \$(parse_git_branch)> \\[$(tput sgr0)\\]"
When I sudo to su, it looks like my PS1 is carried over, and after every command I get the error bash: parse_git_branch: command not found
.
What can I change so that when I sudo to another user, its PS1 is used and not that of my user?
Edit: It seems like this only happens after I use source a Python virtualenv. If I sudo su before I source the virtualenv, this error does not occur.
.profile
is only read by login shells.sudo su
has the normal PS1.