Customize Prompt On Mac OS X

After my entry on Command Line Text To Speech, I realized that my command prompt is looking pretty sad.

I decided to spruce it up a bit and do something about the excessively long “brad-jaspers-powerbook-g5-15″ string.

I wanted something that was shorter but also gave me the time, so I decided on:

Picture 10

To get this effect, I opened ~/.bash_profile and added the line:

export PS1='\u:\@:\w> '

After logging out and back in, you’ll be greeted with your new terminal.

Here’s a whole list of switches to help you customize your prompt:

\a an ASCII bell character (07)
\d the date in “Weekday Month Date” format (e.g., “Tue May 26″)
\e an ASCII escape character (033)
\h the hostname up to the first `.’
\H the hostname
\n newline
\r carriage return
\s the name of the shell, the basename of $0 (the portion following the final slash)
\t the current time in 24_hour HH:MM:SS format
\T the current time in 12_hour HH:MM:SS format
@ the current time in 12_hour am/pm format
\u the username of the current user
\v the version of bash (e.g., 2.00)
\V the release of bash, version + patchlevel (e.g., 2.00.0)
\w the current working directory
\W the basename of the current working directory
\! the history number of this command
# the command number of this command
\$ if the effective UID is 0, a #, otherwise a $
\nnn the character corresponding to the octal number “nnn”
\\ a backslash
\[ begin a sequence of non_printing characters
\] end a sequence of non_printing characters

Note: This is only for the bash shell.

Technorati Tags:


 
 

8 Responses to “Customize Prompt On Mac OS X”

  1. 4Avatars
    james
    "brad-jaspers-powerbook-g5-15"

    a little wishful thinking on that "g5" there, eh?


  2. 4Avatars
    jh
    How about the colored bits below the command prompt?
    I've noticed that when I do an 'ls' on my own mac it tends to be monochromatic, however, when I'm ssh-d in to a linux machine and 'ls' I tend to get output that colors directories, and executables differently.
    Why is this? And is there any way to get my own mac's output to be color coded as well?



  3. Trackback
    Zivo NiX BLog » Customize Prompt On Mac OS X

    [...] Prompt On Mac OS X In the comments of Customize Prompt On Mac OS X, jh asks how to color your command prompt: How about the colored bits below the command prompt? [...]


  4. 4Avatars
    plus.tw
    I think the \w should be \W (the upper case)
    export PS1='\u:\@:\W> '


  5. Trackback
    Color Your OS X Command Prompt - MacTips: OS X Tips & Tricks

    [...] the comments of Customize Prompt On Mac OS X, jh asks how to color your command prompt: How about the colored bits below the command [...]



  6. Trackback
    Git Branch in Command Line « BJS Test Blog

    [...] and proceeded to spruce up my command line with the knowledge in Maddox’s post and in MacTip’s Customize Prompt on OS X article. The long and short of it is that the colors in my command prompt bother me so I cut them out of [...]


Post a comment to "Customize Prompt On Mac OS X"



Support MacTips

MacTips Newsletter


Random Popular Tips

Recent Comments

Recent Discussions

MacTips Poll

What level of tips would you like to see?

View Results

Loading ... Loading ...

Friends of MacTips

Subscribe to MacTips

Site Links