Want to change the text, information displayed, and colors in your bash prompt?

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/cc5da6bf-b510-4f03-af06-92a7eb4836f9/ScreenShot2019-01-20at5.12.15PM.png

One more example:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/158ef658-2be2-4f46-b836-7a2b6adc5b9e/ScreenShot2019-01-20at5.29.46PM.png

Step 1: The PS1 variable

Set the PS1 variable to control your prompt. Try entering this into your shell:

PS1="Go Away -> "

Common Special Characters

To add in dynamic information like the date or hostname, we can use a set of special characters:

\\d - the current date \\e - escape character \\h - the hostname \\n - a newline \\t - current time 24-hour HH:MM:SS \\T - 12-hour HH:MM:SS \\@ - 12-hour HH:MM am/pm \\u - username of current user \\w - path to current working directory

For example, to display your username:

PS1="I am \\u "

Colors!

Most shells come with a minimum of 8 standard color codes (yes they are very ugly 🤮)

Black: \\e[30m Blue: \\e[34m Cyan: \\e[36m Green: \\e[32m Magenta: \\e[35m Red: \\e[31m White: \\e[37m Yellow: \\e[33m

Black: \\033[30m Blue: \\033[34m Cyan: \\033[36m Green: \\033[32m Magenta: \\033[35m Red: \\033[31m White: \\033[37m Yellow: \\033[33m

We need to enclose our color codes using the following escape sequences:

\\[ - start of non-printing sequence \\] - end of non-printing sequence

To make our prompt yellow...