3
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.
maybe moving this functuon form bashrc to .profile could solve the problem - try it out. – mnmnc – 2013-03-21T15:30:42.830
@mnmnc
.profile
is only read by login shells. – terdon – 2013-03-21T15:41:30.727What error are you getting? It seems to cause no problems on my system.
sudo su
has the normal PS1. – terdon – 2013-03-21T15:42:47.123@terdon I'm not getting any errors other than "command not found" when I sudo su. – skyler – 2013-03-21T15:44:33.673
Actually 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. – skyler – 2013-03-21T15:46:40.007