How to customize the shell prompt
11 Aug 2009Depending on your system, you put this into your .bashrc, .bash_login or .profile in your home directory.
export PS1="\[\033[1;34m\]\h\[\033[1;30m\]:\w \[\033[0;30m\]"The code starts with
\[\033[followed by one of these colour codes:
| Colour | Code |
|---|---|
| Black | 0;30 |
| Blue | 0;34 |
| Green | 0;32 |
| Cyan | 0;36 |
| Red | 0;31 |
| Purple | 0;35 |
| Brown | 0;33 |
| Blue | 0;34 |
| Green | 0;32 |
| Cyan | 0;36 |
| Red | 0;31 |
| Purple | 0;35 |
| Brown | 0;33 |
and ends with:
m\]There are some switches which can add some infos to your prompt (current path, date, time, etc.):
| \a | an ASCII bell character (07) |
| \d | the date in “Weekday Month Date” format (e.g., “Tue May 26”) |
| \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 |
| \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 $ |
(via mactips.org)
To make folders, files and links coloured when you use ls, put this in one of the above mentioned files:
export LS_OPTIONS="--color=always --human"