For some time I wanted to unify how the Linux prompt is displayed on Order of Code various instances. I wanted it to include the following information:
- Full hostname.
- Path to current directory.
- Displayed as
- Soothing light-green colour for normal user.
- Red colour for elevated user so that he should be extra careful.
- Work for all users on the server.
While including all this info might be too much, it might prevent some nasty accidents. Deleting database on wrong server, destroying wrong VM and so on.
Achieving prompt syntax was easy enough with various generators available online. The only tricking part was elevation based coloring having the prompt server wide.
It turns out that there is a nice and neat solution for achieving that. Centos, and other distributions, stores various node-wide scripts in
So all I had to do is to put another one that contains instructions on how to format and colour the prompt. I decided to name it
Its logic was super simple: if user ID is different than 0 display prompt in green. If it is (that means elevated to root) then use red.
# This script unifies prompt syntax and coloring for all users on the server
# By default regular users will have prompt in green
# Root user will have red prompt to know that stuff just got real
if [[ $EUID -ne 0 ]]; then