|Bash Prompt HOWTO: $Revision: 0.89 $, $Date: 2001/08/22 00:57:34 $|
|Prev||Chapter 4. External Commands||Next|
You'll find I put username, machine name, time, and current directory name in most of my prompts. With the exception of the time, these are very standard items to find in a prompt, and time is probably the next most common addition. But what you include is entirely a matter of personal taste. Here is an interesting example to help give you ideas.
Dan's prompt is minimal but very effective, particularly for the way he works.
[giles@nikola:~]$ cur_tty=$(tty | sed -e "s/.*tty\(.*\)/\1/") [giles@nikola:~]$ echo $cur_tty p4 [giles@nikola:~]$ PS1="\!,$cur_tty,\$?\$ " 1095,p4,0$
Dan doesn't like that having the current working directory can resize the prompt drastically as you move through the directory tree, so he keeps track of that in his head (or types "pwd"). He learned Unix with csh and tcsh, so he uses his command history extensively (something many of us weaned on Bash do not do), so the first item in the prompt is the history number. The second item is the significant characters of the tty (the output of "tty" is cropped with sed), an item that can be useful to "screen" users. The third item is the exit value of the last command/pipeline (note that this is rendered useless by any command executed within the prompt - you could work around that by capturing it to a variable and playing it back, though). Finally, the "\$" is a dollar sign for a regular user, and switches to a hash mark ("#") if the user is root.