Change your shell prompt

The same way we added colors to the text in terminal application in Mac OS X, you can change the default shell prompt to something more meaning full to your needs. By default it looks something like this:

enekochans-Mac-mini:Users enekochan$

As you can see it is defined as:

"host name":"current working directory" "user name"$

You can change it by modifiying the $PS1 system variable. Those a some of the placeholders but there are a lot more:

  • d – Current date
  • t – Current time
  • h – Host name
  • # – Command number
  • u – User name
  • W – Current working directory (ie: Desktop/)
  • w – Current working directory, full path (ie: /Users/Admin/Desktop)

You can guess that the default value of $PS1 is configured as follows:

EXPORT PS1="h:W u$ "

You can set you own value in ~/.bashrc or ~/.bash_profile.

You can also change the default interactive prompt for a multi-line command which is “>” by changing $PS2 system variable.

Ref: http://www.thegeekstuff.com/2008/09/bash-shell-take-control-of-ps1-ps2-ps3-ps4-and-prompt_command/
http://osxdaily.com/2006/12/11/how-to-customize-your-terminal-prompt/

You might also like

Add colors to the text in terminal application in Mac OS X
Just add the following 2 lines to your /etc/profile, ~/.profile or ~/.bash_profile:export CLICOLOR=1 export...

Add colors to the text in terminal application in Mac OS X
Just add the following 2 lines to your /etc/profile, ~/.profile or ~/.bash_profile:export CLICOLOR=1 export...

Turn on syntax highlighting for vi and vim in Mac OS X
Turning syntax highlighting for vi and vim in Mac OS X is as simple as creating a file called ".vimrc"...

Turn on syntax highlighting for vi and vim in Mac OS X
Turning syntax highlighting for vi and vim in Mac OS X is as simple as creating a file called ".vimrc"...

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.