Practical and interesting bash command prompt line

Source: Internet
Author: User
Tags command prompt codes

Practical and interesting bash command prompt line

 

The color and so on can be used freely.


1. Add a smiley face symbol to the successfully executed command:

 

If the command is successfully executed, you will receive a smiling face as your command line prompt. Once the command fails, the command line prompt will be replaced with a crying face. Flash and highlight.

 

PS1 = "\ 'If [\ $? = 0]; Then ECHO \ [\ e [40 \; 33 \; 5 \; 1m \] ^ _ ^ \ [\ e [0m \]; else echo \ [\ e [40 \; 31 \; 5 \; 1m \] @ [email protected] \ [\ e [0m \]; FI \ '[\ [email protected] \ H: \ W] \ $"

Echo 'export PS1 = "\ 'If [\ $? = 0]; Then ECHO \ [\ e [40 \; 33 \; 5 \; 1m \] ^ _ ^ \ [\ e [0m \]; else echo \ [\ e [40 \; 31 \; 5 \; 1m \] @ [email protected] \ [\ e [0m \]; FI \ '[\ [email protected] \ H: \ W] \ $ "'>/etc/bashrc

./Etc/bashrc

 

 

 

2.Change the color of the failed command

 

I personally like this.

 

The color of the command line prompt will change after your last command fails to run, and the long path of the command will shorten the space for entering the command, this command prompt also contains the command numbers of each history bash command to facilitate re-extraction and running.

 

PS1 = "\ [\ 033 [40; 33; 1m \] [\!] \ 'If [[\ $? = "0"]; then Echo "\ [\ 033 [32m \]"; else echo "\ [\ 033 [31m \]"; FI \ '[\ [email protected] \ H: \ 'If [['pwd | WC-c | tr-d ""'> 18]; then ECHO "\ W"; else echo "\ W"; FI \ '] \ $ \ [\ 033 [0m \] "; echo-ne "\ 033] 0; 'hostname-s': 'pwd' \ 007"

Echo 'export PS1 = "\ [\ 033 [40; 33; 1m \] [\!] \ 'If [[\ $? = "0"]; then Echo "\ [\ 033 [32m \]"; else echo "\ [\ 033 [31m \]"; FI \ '[\ [email protected] \ H: \ 'If [['pwd | WC-c | tr-d ""'> 18]; then ECHO "\ W"; else echo "\ W"; FI \ '] \ $ \ [\ 033 [0m \] "; echo-ne "\ 033] 0; 'hostname-s': 'pwd' \ 007" '>/etc/bashrc

./Etc/bashrc

 

 

3. multiline prompt:

 

PS1 = "\ n \ [\ 033 [35m \] \ $ (/bin/date) \ n \ [\ 033 [32m \] \ W \ n \ [\ 033 [1; 31m \] \ [email protected] \ H: \ [\ 033 [1; 34m \] \ $ (/usr/bin/tty |/bin/sed-E's #/dev/# '): \ [\ 033 [1; 36m \] \ $(/bin/LS-1 |/usr/bin/WC-L |/bin/SED's ### G ') files \ [\ 033 [1; 33m \] \ $ (/bin/LS-lah |/bin/grep-M 1 Total |/bin/SED's/total //') B \ [\ 033 [0m \]-> \ [\ 033 [0m \]"

Echo 'ps1 = "\ n \ [\ 033 [35m \] \ $ (/bin/date) \ n \ [\ 033 [32m \] \ W \ n \ [\ 033 [1; 31m \] \ [email protected] \ H: \ [\ 033 [1; 34m \] \ $ (/usr/bin/tty |/bin/sed-E's #/dev/# '): \ [\ 033 [1; 36m \] \ $(/bin/LS-1 |/usr/bin/WC-L |/bin/SED's ### G ') files \ [\ 033 [1; 33m \] \ $ (/bin/LS-lah |/bin/grep-M 1 Total |/bin/SED's/total //') B \ [\ 033 [0m \]-> \ [\ 033 [0m \] "'>/etc/bashrc

./Etc/bashrc

 

 

 

 

4. multi-color prompt:

 

 

PS1 = "\ [\ 033 [40; 33; 1m \] \ t \ [\ 033 [M \]-\ [\ 033 [40; 36; 1 m \] \ U \ [\ 033 [M \] @ \ [\ 033 [40; 32; 1 m \] \ H: \ [\ 033 [33; 1 m \] \ W \ [\ 033 [M \] \ $"

Echo 'ps1 = "\ [\ 033 [40; 33; 1m \] \ t \ [\ 033 [M \]-\ [\ 033 [40; 36; 1 m \] \ U \ [\ 033 [M \] @ \ [\ 033 [40; 32; 1 m \] \ H: \ [\ 033 [33; 1 m \] \ W \ [\ 033 [M \] \ $ "'>/etc/bashrc

./Etc/bashrc

 

 

 

5. display the complete path:

 

2 rows at the minimum (plus the empty rows at the top ). In the first line, you can get a full path information, and in the second line, you can get a user name. If you are uncomfortable with the empty lines in each command prompt line, you just need to remove the first \ n and it will be OK.

 

PS1 = "[\ [\ 033 [40; 32; 1m \] \ W] \ [\ 033 [0m \] \ n \ [\ 033 [1; 36m \] \ U \ [\ 033 [1; 33m \]-> \ [\ 033 [0m \]"

Echo 'ps1 = "[\ [\ 033 [40; 32; 1m \] \ W] \ [\ 033 [0m \] \ n \ [\ 033 [1; 36m \] \ U \ [\ 033 [1; 33m \]-> \ [\ 033 [0m \] "'>/etc/bashrc

./Etc/bashrc


 

 

6. display the number of running tasks in the background:

 

PS1 = "\ [\ 033 [40; 32; 1m \] \ [email protected] \ H: \ [\ e [M \] \ [\ e [1; 37m \] \ W \ [\ e [M \] \ n \ [\ e [1; 33m \] hist :\! \ [\ E [0; 33m \] \ [\ e [1; 31m \] jobs: \ J \ $ \ [\ e [M \]"

Echo 'ps1 = "\ [\ 033 [40; 32; 1m \] \ [email protected] \ H: \ [\ e [M \] \ [\ e [1; 37m \] \ W \ [\ e [M \] \ n \ [\ e [1; 33m \] hist :\! \ [\ E [0; 33m \] \ [\ e [1; 31m \] jobs: \ J \ $ \ [\ e [M \] "'>/etc/bashrc

./Etc/bashrc

 

 

7. Display path information:

 

PS1 = "\ n \ [\ e [30; 1m \] \ [\ 016 \] l \ [\ 017 \] (\ [\ e [34; 1 m \] \ [email protected] \ H \ [\ e [30; 1 m \])-(\ [\ e [34; 1 m \] \ J \ [\ e [30; 1 m \])-(\ [\ e [34; 1 m \] \ @ \ D \ [\ e [30; 1 MB \])-> \ [\ e [30; 1 m \] \ n \ [\ 016 \] m \ [\ 017 \]-(\ [\ [\ e [32; 1 m \] \ W \ [\ e [30; 1 m \])-(\ [\ e [32; 1 m \] \ $(/bin/LS-1 |/usr/bin/WC-L |/bin/SED's: G') files, \ $ (/bin/LS-lah |/bin/grep-M 1 Total |/bin/SED's/total // ') B \ [\ e [30; 1 MB \])-> \ [\ e [0m \]"

 

 

 

 

8.

 

PS1 = "\ n \ [\ e [32; 1m \] (\ [\ e [37; 1m \] \ U \ [\ e [32; 1m \]) -(\ [\ e [37; 1m \] jobs: \ J \ [\ e [32; 1m \])-(\ [\ e [37; 1 m \] \ W \ [\ e [32; 1 m \]) \ n (\ [\ e [37; 1 m \]! \! \ [\ E [32; 1m \])-> \ [\ e [0m \]"

 

 

 

 

9.

 

PS1 = "\ [\ e [1; 34m \] \ U \ [\ e [M \] \ [\ e [1; 31m \] @ \ [\ e [M \] \ [\ e [1; 33m \] \ H \ [\ e [M \] \ [\ e [1; 34m \]: \ [\ e [M \] \ [\ e [1; 32m \] \ W \ [\ e [M \] \ [\ e [1; 32m \] \ n (\ [\ e [37; 1m \]! \! \ [\ E [32; 1m \]) \ [\ e [M \] \ [\ e [1; 35m \] $ \ [\ e [M \]"

 

See http://coolshell.cn/articles/1399.html.

If you are willing to share your command prompt line, please add these command prompt codes to the comments below to share with you the broad mind.

 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.