- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to decorate your Linux Terminal using Shell?
The Linux GUI based terminal window has many colours and font settings which can be enhanced as per the user choice. All these can be done using the shell commands and not just by clicking mouse buttons in the GUI component settings.
Most of these settings are handled through variables whose value can be changed or assigned by commands. In this article we will see how to handle the terminal prompt settings in Ubuntu based systems.
The PS1 Variable
It is a environment variable which controls the primary prompt string which is displayed when the shell is ready to read a command. There are many backslash-escaped special characters whose value decide the display that will come out at the prompt. Let’s first see the value of the current prompt.
$ echo $PS1
Running the above code gives us the following result −
\[\e]0;\u@\h: \w\a\]
The above format describes the different arguments that decide what is displayed at the PS1 prompt. Below is example of some of the such arguments which are most widely used in setting up the environment prompt.
\u: the username of the current user.
\h: the hostname up to the first dot (.) in the Fully-Qualified Domain Name.
\W:the basename of the current working directory, with $HOME abbreviated with a tilde (~).
\$: If the current user is root, display #, $ otherwise.
Customizing the PS1 Prompt
The PS1 promopt has features to assign various colours to the values like hostname, username etc. The below commands show an example of how they are applied. We use the \e special character at the beginning and an m at the end to indicate that what follows is a color sequence.
We can customize the following three aspects of the prompt.
Text Settings
Value | Meaning |
---|---|
0 | Normal Text |
1 | Bold Text |
4 | Underlined Text |
Text Colours
Value | Meaning |
---|---|
30 | Black |
31 | Red |
32 | Green |
33 | Yellow |
34 | Blue |
Background Colour
Value | Meaning |
---|---|
40 | Black |
41 | Red |
42 | Green |
43 | Yellow |
44 | Blue |
But all these customizations are temporary. As soon as the user comes out of the terminal, these customizations are lost. To set them permanently, we need to add these to the. bashrc profile of the user.