PS1 Bash prompt with colors
How to create a custom (Bash) PS1 prompt. (For a custom GIT prompt, look here: Git PS1 Prompt)
Example of a simple PS1 prompt:
marc@server:~/$
This is like the most default prompts when you install Linux, some may look a bit different but most likely nothing more. To Customize the PS1, you need to know what to change and what to use, here is a list with some info about
the letters used in PS1.
d - the date in "Weekday Month Date" format (e.g., "Tue May 26")
e - an ASCII escape character (033)
h - the hostname up to the first .
H - the full hostname
j - the number of jobs currently run in background
l - the basename of the shells terminal device name
n - newline
r - carriage return
s - the name of the shell, the basename of $0
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
A - the current time in 24-hour HH:MM format
u - the username of the current user
v - the version of bash (e.g., 4.00)
V - the release of bash, version + patch level (e.g., 4.00.0)
w - Complete path of 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 $
nnn - the character corresponding to the octal number nnn
\ - a backslash
[ - begin a sequence of non-printing characters, which could be
used to embed a terminal control sequence into the prompt
] - end a sequence of non-printing characters
So for example, you could do something like this:
export PS1="\e[0;34m\u@\h \w> \e[m"
This will give you a full lightblue PS1 prompt. To add more colors try:
export PS1="\e[0;31m\u\e[0;33m@\e[0;34m\h \e[0;34m\w> \e[m"
This will look like:
marc@host /tmp>
Now i know what you think, you just want a great PS1, this is possible due to some guys which created a few online bashrc generators.
I’ve used this one a few times:
Bashrc Generator
Easy to use and it will give you really nice PS1 prompts.