Want to change the text, information displayed, and colors in your bash prompt?
One more example:
Set the PS1 variable to control your prompt. Try entering this into your shell:
PS1="Go Away -> "
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 "
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...