## Monday, December 17, 2007

### Fixing the "ever-changing prompt problem" on Mac OS X 10.4

The other day I fired xterm while hooked on my home Internet access, and found the hostname on my prompt changed from the machine name to some strange letters-and-numbers string. Apparently this is a known issue, and the traditional solution is to hard code the machine name into the prompt; there is, however, a more ellegant way. Using the scutil command to get the machine name from your System Preferences, not only will you get the right name, but it will also consistently reflect your Sharing settings.

The syntax for getting the machine name with scutil:

scutil --get ComputerName

So, for example, to have a prompt containing the user name, the machine name and the current directory, we could add to our startup script something like:

PS1='[\u@scutil --get ComputerName:\W]\\$ '

Were you to ever change your machine name, this configuration would automatically reflect it on your terminal prompt.