I'd like to source my
.bash_profile (or maybe some other file) whenever I switch to superuser. (
.bash_profile is the login rc on Mac OS X,
.bashrc is the non-login script, and
.profile is a login rc that runs for any shell).
.bash_profile makes using a terminal more convenient for me, and on those occasional times when I have to go super, I feel like I'm trying to play a guitar without thumbs. More than that,
$PROMPT_COMMAND get exported to the super user, but functions defined in my
.bash_profile and used in my
$PROMPT_COMMAND do not get exported to that lexical environment.
In particular, I source the
git-prompt.sh script in my
.bash_profile and use the exported
__git_ps1 command in my
$PROMPT_COMMAND. Thus, every single prompt line in the superuser shell is preceded by the warning:
bash: __git_ps1: command not found.
Now I technically could modify the system-wide rc in
/etc/profile in order to achieve the effect. I could look at
$HOME, and if it's my home, then source
$HOME/.bash_profile. However, this isn't portable. I would have to modify the
/etc/profile on every host in which I'm likely to be working. I want to export this behavior to happen on all hosts on which I work.
Can anyone think of a solution that is completely contained in my own bash profile?
No warnings about becoming a super user are necessary. I know there's
sudo, and that it's bad, bad, bad, and I'm morally and intellectually inferior for doing it. :)
Mac OS X's
su doesn't have the
-c option, which would have been a pretty good solution.