Customize the Mac Terminal Shell Prompt in OS X Yosemite

The Mac prompt is defined by the ‘PS1’ environment variable which can be defined in the ‘.bash_profile’ hidden file. To customize your Mac Terminal Shell Prompt in OS X Yosemite, follow the below steps.

1. Open a terminal window
2. With you favorite editor open the hidden file ‘.bash_profile’ in your home directory. I’ll use ‘vi’ so will type “vi .bash_profile”
3. Add the following line after the last line: export PS1=””

Now, between the quotation marks, you can insert your custom terminal prompt verbiage. You can also use the following escape characters representing special values:
\d – date
\t – time
\h – hostname
\# – command number
\u – username
\W – current directory (e.g.: Desktop)
\w – current directory path (e.g.: /Users/Admin/Desktop)

Once you are done making the changes, save the file. If using ‘vi’, the command to save is [‘esc’ + ‘:’ + ‘wq’ + ‘enter’].

Below is an example of the original prompt on my MacBook Pro running OS X Yosemite.

Original prompt on my MacBook Pro running OS X Yosemite

Original prompt on my MacBook Pro running OS X Yosemite

Below is a snapshot of my edited ‘.bash_profile’ file.

Edited Mac OS X Yosemite '.bash_profile' file

Edited Mac OS X Yosemite '.bash_profile' file

Once I start a new shell, you can see from the below my shell prompt has changed as expected.

Customized Mac Terminal Shell Prompt in OS X Yosemite

Customized Mac Terminal Shell Prompt in OS X Yosemite



Follow me on Twitter: @Humair_Ahmed

This entry was posted in Mac OS X Yosemite, Operating Systems, Technology and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


nine + = 13