OS X Terminal - Prompt Format Posted on June 07, 2007 by Dave Fowler
As I've alluded to previously I like to customize my terminal as I spend plenty of time in it. I typically go with an old school green on black, though sometimes I go with a simple black on white depending on my mood. A lot of terminal settings unfortunately aren't customizable from the preferences. One such setting is the format of the command prompt. I was getting really anoyed with the wrapping length of mine today.
Just not acceptable. Luckily OS X Daily came through with the solution. They use some non-default steps however so here are my recomendations. I'm assuming you're using a bash prompt which starts up running .profile (if you're not sure, you probably are). Open your .profile file with the following
$ emacs ~/.profile
Add the following command somewhere in the opened file.
export PS1="\u@\h-\W$ "
Now press Ctl-X Ctl-S to save it and then Ctl-X Ctl-C to close back to your terminal. To load the settings re-source your .profile with
$ source ~/.profile
The setting will change your command prompt to [user name]@[host name]-[current dir]. It should look something like this...
So much better now. If you don't like mine you can make your own format by changing whatever's between the quotes. The following variables can be used:
\d - Current date
\t - Current time
\h - Host name
\# - Command number
\u - User name
\W - Current working directory
\w - full path
As you can see the default must have been "\h:\w \u". Thank god we're rid of that! It was so long...
As a bonus tip, if you don't like your host name for some reason like your computer still isn't smart enough to notice obvious typos like Dave-Fowers-Computer you can change it in System Preferences > Sharing > Computer Name. Might I recommend the name Jared. For some reason it always makes me feel more safe.
Hope you enjoyed one of the thingsilearned today.
Dave