Changing your bash prompt hostname in Tiger

Robert Daeley
Oct. 25, 2005 12:51 PM
Permalink

A tip for those who are running Tiger and want to change the hostname that shows up in their terminal prompt.
In the past, on pre-Tiger systems, folks were told to edit their /etc/hostconfig file and change the hostname variable from AUTOMATIC to yourhostnamehere. This was to forestall the ever-changing prompt problem, which annoys laptop users who move from network to network and could find themselves 'jsmith@dhcp-123.45.6.7' or 'jsmith@nameofbox' or any number of things, depending on where they were.
That HOSTNAME=-AUTOMATIC- variable is missing from a fresh install of Tiger, however, and from what I've been able to research, Tiger no longer uses it anyway. :) But rather than bothering with that, you can just edit the way your prompt looks using your .bash_profile file.
Bash is the Bourne Again Shell, the usual default CLI shell on Linux and (nowadays) Mac. Which is handy if you flit between the OSs. You can control various options for your Terminal experience inside an invisible file named '.bash_profile' in your home directory. Invisible to the Finder, at least, but editable from within the Terminal. So if it doesn't exist, you can create it using vim or nano or emacs or whatever your favorite CLI text editor is.
Add these lines to .bash_profile to get the unchanging hostname and a little bit of enhancement from the default prompt, assuming you wanted the hostname to be 'mithrandir':
PS1="[\u@mithrandir:\w] " case `id -u` in 0) PS1="${PS1}# ";; *) PS1="${PS1}$ ";; esac
Prompt-futzing is a dear old tradition in geek circles and a good example of the true necessity of spending a few hours hacking in order to save less than a minute every day. :)
Robert Daeley
is a writer and programmer in Southern California. By day he is a mild-mannered server administrator and website developer; by night, in addition to his super-hero duties, he cooks, bikes, hikes, cheers on the Dodgers, and writes fiction.
Got any favorite CLI prompt futzes?
You must be logged in to the O'Reilly Network to post a comment.
Showing messages 1 through 3 of 3.
-
just set your hostname in Sys Prefs
2005-10-27 02:25:43
carlj7
[Reply | View]
-
I like this...
2005-10-25 14:05:49
harleycooper
[Reply | View]
|
Showing messages 1 through 3 of 3.
|
Return to weblogs.oreilly.com.
Weblog authors are solely responsible for the content
and accuracy of their weblogs, including opinions they
express, and O'Reilly Media, Inc., disclaims any and
all liabililty for that content, its accuracy, and
opinions it may contain.
This work is licensed under a
Creative Commons License.
|
In System Preferences, your hostname can be set in the Sharing panel.
Anyhow, since it's apparently cool to show off your bash prompt, here's mine:
export prompt="%{\033[30;43m%}%~ %%%{\033[0m%} "Which yields a bright green "[cjohnson@albook:~/tmp]$ " followed by darker green input text.