Change your 'root' prompt for safety

May 17, '01 11:11:43AM

Contributed by: robg

Thanks to Keith O. for this one...

If you occasionally use the terminal as root, you should consider using a different prompt when 'rooted' - this will help you remember that you are working as root, and hopefully prevent you from doing something that you didn't intend to do.

The first step is to create a file named .tcshrc in /var/root (this file could also probably be created as /var/root/Library/init/tcsh/rc.mine, but I haven't tried that). You'll be placing your prompt in this file, so that it gets loaded each time you start a root session. Here's what Keith O. placed in his root .tcshrc file:

set prompt="%{\033[32m%}%n @ %/ on $host %#%{\033[30m%}  "
This changes the content and color of the prompt, so that it differs from that of his normal user. If that looks completely foreign to you, that's perfectly normal! Read this hint for a general overview of prompt variables, including an explanation of the color codes, which should help clear things up (a little!).

You can experiment all you like in a terminal session - whatever you set as prompt will only last until you change it again or close the session. It only becomes permanent when you place it in root's .tcshrc file. Also read the referenced hint for setting your normal user's prompt. You can do some pretty neat stuff once you figure out the structure. For instance, this is my normal prompt string:
set prompt="%{\033[0;1;32m%}[%{\033[36m%}%t %n%{\033[32m%}%{\033[33m%}[space]
%c3%{\033[32m%}]%{\033[0m%}%# "
Note: Replace [space] with the actual space character, and enter on one line; broken for easier display. That prompt string leads to this prompt display:



The colors help the prompt stand out from the text that flows as the result of whatever command I'm running. Customizing your prompt string (for both your normal user and root) is a good way to make your time in the terminal more productive.

Comments (9)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20010517111143173