advertisement

Search


Sponsored Developer Resources

Atom 1.0 Feed RSS 1.0 Feed RSS 2.0 Feed


Webloggers
Login
Home




Changing your bash prompt hostname in Tiger

   Print.Print
Email.Email weblog link
Discuss.Discuss
Blog this.Blog this
Robert Daeley

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

Atom feed for this author. RSS 1.0 feed for this author. RSS 2.0 feed for this author.

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.

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.

Creative Commons License This work is licensed under a Creative Commons License.



Sponsored by:



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 liability for that content, its accuracy, and opinions it may contain.

For problems or assistance with this site, email