Many people are not concerned about the importance of command line prompts. But I do not think so at all. A good command line prompt can change the way you use commands. To this end, I found some useful, excellent, and interesting bash command line prompts on the internet. Below I will list some of my favorite command line prompts as follows.
Note-to use the following prompts, you can copy and paste the headers starting with "PS1" to your terminal. In order to make your changes take effect permanently, also paste the content to your user's ~ /. Bashrc file.
1. Add a smiley face symbol to the successfully executed command.
This command prompt line may be the most interesting one in the command line prompt list, but it is still useful. The idea behind this prompt is that when your command is successfully executed, you will get a smiling face as your command line prompt. Once the command execution fails, the command line prompt will change to a crying face.
Example:
Code:
PS1 = "\ 'if [\ $? = 0]; then echo \ [\ e [33m \] ^ _ ^ \ [\ e [0m \]; else echo \ [\ e [31m \] O_O \ [\ e [0m \]; fi \ '[\ u @ \ h: \ w] \ $"
2. Change the color of the failed command
The following command line prompt is one of my favorite command lines. Similar to the previous one, 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.
Example:
Code:
PS1 = "\ [\ 033 [0; 33m \] [\!] \ 'If [[\ $? = "0"]; then echo "\ [\ 033 [32m \]"; else echo "\ [\ 033 [31m \]"; fi \ '[\ u. \ 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 ″'
3. multiline prompt
If you like the type of person with complete information in the command line prompt, there will be a command line prompt below for you. The command line prompt contains the date/time, full path, user, host, activity terminal, and even the number of files and occupied space.
Example:
Code:
PROMPT_COMMAND = 'ps1 = "\ n \ [\ 033 [35m \] \ $ (/bin/date) \ n \ [\ 033 [32m \] \ w \ n \ [\ 033 [1; 31m \] \ u @ \ 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 \]''
4. multi-color prompt
This command line prompts that apart from using different colors to differentiate different information, it is not very special. As you can see, it provides the time, user name, host name, and current directory. Very little information, but very practical.
Example:
Code:
PS1 = "\ [\ 033 [35m \] \ t \ [\ 033 [m \]-\ [\ 033 [36m \] \ u \ [\ 033 [m \] @ \ [\ 033 [32m \] \ h: \ [\ 033 [33; 1 m \] \ w \ [\ 033 [m \] \ $"