Skip to main content

HOW TO MAKE YOUR TERMUX COLORFUL WITH PS1

The word PS1 is an acronym for  PROMPT STRING1 which is used for shell configuration using runnable little code commands sequence . You see Termux which is a Linux base terminal emulator helps give  us a lot of opportunities to do almost everything you can do on a real Linux command line environment, Wow are you shocked?  yeah many think that termux is only for hacking but there more to it because with termux we can do a lot of other things like text editing, play games, write real time script and lots more. 

We will be talking about how to make your terminal look cool. let's start with something interesting. 
    

                   Color codes     

This part may seem a bit confusing but don't worry we will go through it one after the other 


Sequence                                    color 

1. \033[0;30m                            black 

2. \033[0;31m                            Red 

3. \033[0;32m                           Green 

4. \033[0;33m                           Brown 

5. \033[0;34m                          Blue 

6. \033[0;35m                          Purple 

7. \033[0;31m                          cyan 

8. \033[0;37m                         light gray    


Now that we have seen the eight color  codes that we be working with let's see another cool set of PS1  code which will help us take control of the our shell. 

         PS1  ESCAPE SEQUENCE CODES

1. \a         Ascii bell .This will make the                          terminal beep when ever it' s                         encountered     .

2. \d        current date (day:month)  formate                  .eg mon may 26      

3. \h        Hostname of the local machine

4. \H       full hostname 

5. \n        Newline

6. \T       Current time in 12 hrs format

7. \t         Current time in 24 hrs format

8. \@       The current time in 12 format                         with  AM/PM 

9. \w          Name of the current working                         directory

10. \u          Username of the current user

11. \$         Displays $ or # if in super user                       privileges

12. \[        This help to start the PS1  code.                   All of our codes are going to be                     written inside it.  

13. \]      This closes our code .


There are other PS1  escape sequence code but we covering only the  basic ones today. let's drive right into it and have fun. 

To change our terminal color

$ PS1="\[  \] "
All of our above listed color codes are going to be written inside in between those two brackets. 

$ PS1="\[\033[0;31m\]\$ "


This will change the color of our terminal to Red pretty cool right? but let me explain our code. 

$ PS1=\[     This will start the code                                     sequence  . 

\033[0;31m  This will is the color code for                          red . 

\]                    This will tell  the terminal                               that this is where our                                       code ends.      

\$                  To display the $ sign. 

"  "                 All of our PS1  code must be                          put on this in order to work.  


Let's try another color, this one is my favorite color. 

$ PS1=" \[\033[0;33m\]\$ "  

This will change our terminal color to yellow. you can play around with different colors. 

NOTE : when you end the current session the color will go out . 

Let's look at PS1 Escape sequence codes  

Let's say want to know the current date the PS1  can help us with that 

$ PS1="\d\$ "  

  Wow was really fun let's another fast one. What if we want the shell to display our current working directory. 

 $ PS1=" \w\$ "  
  when I click the enter button this is what we get


The leading tairl shows that we are in our home directory and if you should change to a different directory the ~ will change to the name of the directory. 

You can have fun play around on the termux terminal once you want to stop it just close the current session. 

let me know what on your mind on the comment section. Have a nice day. 
 
Am I very passionate young man who believes that he can change the world with God and Technology

Comments