Sample of BASH through a shell in GNOME. Screenshot taken in Arch Linux (Photo credit: Wikipedia) |
I would have to say that knowing that I am a root user, or that I activated my being a root user, at least in the prompt, to be a big help. Fortunately, somebody has already thought of this, and has also done it, and has shared it.
So either you are the root user, or you can switch between a normal user and a root user, it would be very beneficial to know when a user mode or privelege is active and available.
That being said, I searched the web, and I found one that worked.
It is editing .bashrc and appending these:
# Turn the prompt symbol red if the user is root
if [ $(id -u) -eq 0 ];
then # you are root, make the prompt red
PS1="[\e[01;34m\u @ \h\e[00m]----[\e[01;34m$(pwd)\e[00m]\n\e[01;31m#\e[00m "
else
PS1="[\e[01;34m\u @ \h\e[00m]----[\e[01;34m$(pwd)\e[00m]\n$ "
fi
So the .bashrc could be in your /home/username directory.
Or when you invoke superuser by sudo -i (or sudo su), it would be in /root directory.
By employing this, I am able to know when I am a normal user, and when I am a super user. It may be what you need, for all I know. Try it!
Here's the reference: Changing behavior of bash prompt when functioning as root
Till then!
To make the showing of path dynamic, change the double quotes in PS1="asdfghjkl" into single quotes, like so: PS1='asdfghjkl'. That would go for both if and else lines.
ReplyDeleteEnjoy!