Changing your bash prompt hostname in Tiger

by Robert Daeley

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-' 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}$ ";;

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. :)

Got any favorite CLI prompt futzes?


2005-10-25 14:05:49
I like this...
function prompt
local WHITE="\[\033[1;37m\]"
local BRIGHTGREEN="\[\033[1;32m\]"
local GREEN="\[\033[0;32m\]"
local CYAN="\[\033[0;36m\]"
local GRAY="\[\033[0;37m\]"

creates a prompt that looks kinda like
.oO( user@hostname Desktop )
with purty colours...

Matthew Doar
2005-10-26 09:56:33
Adding the CVS branch name to your prompt
If you tend to forget which branch you're working on, this incantation adds (and colors) the branch name to the prompt.

export PS1="[\u@\h\$(if [ -d CVS ]; then if [ -e CVS/Tag ]; then cat CVS/Tag | sed -e 's/^T/ /' | sed -e 's/^N/ /' | sed -e 's/^D/ Date /' | sed -e 's/_BRANCH/\[\033]12;blue\007\]/'; else echo ' \[\033]12;black\007\]MAIN' ; fi; else echo '
\[\033]12;black\007\]' ;fi) \W]\\$ "
2005-10-27 02:25:43
just set your hostname in Sys Prefs

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.

2005-10-27 03:06:15
just set your hostname in Sys Prefs
In System Preferences, your hostname can be set in the Sharing panel.

While that will work, if you get onto a DHCP network the default prompt in a new window will instead show or some variation on that.

2006-01-03 15:22:35
just set your hostname in Sys Prefs
My mac host name is all messed up I think

1. the browser is unable to point to it
2. terminal keeps an old one ie if i made a name1 then changed it to name2, terminal keeps name1 and does not change

i'm using dsl with dhcp

what I find odd is i have the HD partitioned and the local host name works on one partitoned but not the other

is there someplace I can troubleshoot this ?