First we have to open bash profile to locate bash prompt.
It is available in user's home ~
directory by the name .bashrc
.
It is set using $PS1 variable.
In all we have $PS1
, $PS2
, $PS3
and $PS4
variable for the following purposes.
- PS1 – This is the primary prompt display. This is where you set special characters or important information.
- PS2 – This is the secondary prompt string. This is usually set as a divider between the prompt display and the text entry. It is also used to display when a long command is broken into sections with the \ sign.
- PS3 – This is the prompt for the select command.
- PS4 – This is the prompt for running a shell script in debug mode.
we will be changing $PS1
variable
Before Changing You should Create a backup file using the following command.
cp ~/.bashrc ~/.bashrc.bak
To restore run the following command
cp ~/.bashrc.bak ~/.bashrc
Open .bashrc
file in home folder
and change the $PS1 variable as shown below to see changes.
Remember to Save file before closing and apply changes as using source ~/.bashrc
command.
- Set
$PS1 = anytext >
to show the prompt asanytext >
- set
$PS1 = \W >
to show current directory in prompt as~/Desktop/directory >
- set
$PS1 = \u >
to show username in prompt asuser >
- set
$PS1 = \h >
to show hostname in prompt asLaptop123 >
Some of these commands may not work on all versions of Linux.
- \a – A bell character
- \d – Date (day/month/date)
- \D{format} – Use this to call the system to respond with the current time
- \e – Escape character
- \h – Hostname (short)
- \H – Full hostname (domain name)
- \j – Number of jobs being managed by the shell
- \l – The basename of the shells terminal device
- \n – New line
- \r – Carriage return
- \s – The name of the shell
- \t – Time (hour:minute:second)
- @ – Time, 12-hour AM/PM
- \A – Time, 24-hour, without seconds
- \u – Current username
- \v – BASH version
- \V – Extra information about the BASH version
- \w – Current working directory ($HOME is represented by ~)
- \W – The basename of the working directory ($HOME is represented by ~)
- \! – Lists this command’s number in the history
- \# – This command’s command number
- \$ – Specifies whether the user is root (#) or otherwise ($)
- \\– Backslash
- \[ – Start a sequence of non-displayed characters (useful if you want to add a command or instruction set to the prompt)
- \] – Close or end a sequence of non-displayed characters
Color Start Sequence => \[\033[00;32m\]
Color End Sequence => \[\033[00m\]
In Color Start Sequence, we have 00;32m
here 00
is a code that specifies typeface and 32
specifies color.
• 0 – Normal • 1 – Bold (bright) • 2 – Dim • 4 – Underlined
• 30 – Black • 31 – Red • 32 – Green • 33 – Brown • 34 – Blue • 35 – Purple • 36 – Cyan • 37 – Light gray
Additionally, if you combine the bright option with a color code, you get a lighter version of that color. For example, if you use color code 1;32, you would get light green instead of the normal green. If you use 1;33, you get yellow instead of brown.
If your are on gnome Desktop environment, the add the following to the ~/.config/gtk-3.0/gtk.css
file.
VteTerminal,
TerminalScreen,
vte-terminal {
padding: 5px 10px 5px 10px;
-VteTerminal-inner-border: 5px 10px 5px 10px;
}