Special characters to show useful information in $PS1 prompt:
- \h short hostname (without domain).
- \H long hostname.
- \n new line.
- \s shell name (like bash, sh)
- \t 24h format clock.
- \u current username.
- \v shell version.
- \w current folder.
Inside PS1 we can add the output of a specific command, preferably with short output, like PS1=$(date)
We can color the prompt messages just adding \[\033[COLORm\]. and \[\033[0m\] to stop colors to avoid colored commands.
Where COLOR is a secuence with format A; B where A is 0 or 1, and B is a value between 30 and 37. Every combination results in a different color.
$ PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
username@host folder $ # and “username@host” will look in green and folder in blue
Now the list of colors to use:
- 0;30 black
- 0;31 red
- 0;32 green
- 0;33 brown
- 0;34 bluel
- 0;35 purple
- 0;36 cian
- 0;37 grey
- 1;30 dark grey
- 1;31 bright red
- 1;32 bright green
- 1;33 yellow
- 1;34 bright blue
- 1;35 bright purple
- 1;36 bright cian
- 1;37 white
Background colors
- 40 black
- 41 red
- 42 green
- 43 brown
- 44 blue
- 45 purple
- 46 turquoise
- 47 grey
background colors precede letter colors like with:
\[\033[41;1;33m\]
yellow text with red background
Tip: \033 and \e are equivalent, you can choose either.