In ksh:
In my .profile, I set the following var (so this var is only set once per session ever, no matter how many 'su's I do:
PCH=\>
In my .kshrc I have:
if let "${SPID:-0} != $$"; then
PCHS="$PCHS$PCH"
fi
I become root with the following alias, rather than "su" (kroot is a root user with a ksh shell instead of sh (solaris) or bash (linux):
alias root='PCH=\# su -m kroot'
alias me="PCH=\> su -m $USER"
I have also defined these two functions:
function lprompt {
PS1=$HOST' $? $PWD '"$PCHS "
}
function sprompt {
PS1='$?":"${PWD##*/}'"$PCHS "
}
and finally at the end of .kshrc I have:
lprompt
All of this gives me by default automatic setting of the end of my prompt to indicate whether or not I am root (and in turn if I have a parent that was root), current working directory, hostname, and exit status of last process. sprompt drops the hostname, shrinks the path down to only the basename, and removes spaces:
g3 0 /home/jj33 > expr 1 / 0
expr: division by zero
g3 2 /home/jj33 > expr 1 / 1
1
g3 0 /home/jj33 > root
Password:
g3 0 /home/jj33 ># me
g3 0 /home/jj33 >#> ^D
g3 0 /home/jj33 ># sprompt
0:jj33># me
g3 0 /home/jj33 >#> sprompt
0:jj33>#>expr 1 / 0
expr: division by zero
2:jj33>#>
The root/me aliases are bourne from pre-sudo administration on Solaris and old habits have died hard. I doubt anyone would implement the exact same thing these days. The prompt-changing functions and the exist status continue to be very valuable to me.