Assuming you wonβt have git shutdown when you log in to root via sudo su , a little bit of bash kung fu so as not to try to evaluate __git_ps1 .
At the PS1 prompt, you can put any conditional expressions (therefore, how they can be replaced in the branch name when in the git directory). So, just wrap the git stuff in conditional check, you are not user id 0 ( root ).
Replace in your export expression PS1 :
$(__git_ps1)
from
$(if [ $(id -u) -ne 0 ]; then echo $(__git_ps1) ; fi)
Now the entire invitation to the OP will look like this:
PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(if [ $(id -u) -ne 0 ]; then echo $(__git_ps1) ; fi)\[\033[00m\]\$ '
Now in the shell, you can sudo su without reporting an error.
Ray Feb 28 '17 at 0:58 2017-02-28 00:58
source share