"Learning slag Linux Notes" - to change the color output of the ls command and the command prompt color (B)

"Learning slag Linux Notes" - to change the color output of the ls command and the command prompt color (B)

II. Change the color of the command prompt

Command Prompt display format is determined by the PS1 variable, first of all we look for official GNU manuals, find the following (I did not like to write a large section, just want to develop the habit refer to the official manual):

The value of the variable PROMPT_COMMAND is examined just before Bash prints each primary prompt. If PROMPT_COMMAND is set and has a non-null value, then the value is executed just as if it had been typed on the command line.

In addition, the following table describes the special characters which can appear in the prompt variables PS0, PS1, PS2, and PS4:

\a
A bell character.

\d
The date, in "Weekday Month Date" format (e.g., "Tue May 26").

\D{format}
The format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required.

\e
An escape character.

\h
The hostname, up to the first ‘.’.

\H
The hostname.

\j
The number of jobs currently managed by the shell.

\l
The basename of the shell’s terminal device name.

\n
A newline.

\r
A carriage return.

\s
The name of the shell, the basename of $0 (the portion following the final slash).

\t
The time, in 24-hour HH:MM:SS format.

\T
The time, in 12-hour HH:MM:SS format.

\@
The time, in 12-hour am/pm format.

\A
The time, in 24-hour HH:MM format.

\u
The username of the current user.

\v
The version of Bash (e.g., 2.00)

\V
The release of Bash, version + patchlevel (e.g., 2.00.0)

\w
The current working directory, with $HOME abbreviated with a tilde (uses the $PROMPT_DIRTRIM variable).

\W
The basename of $PWD, with $HOME abbreviated with a tilde.

\!
The history number of this command.

\#
The command number of this command.

\$
If the effective uid is 0, #, otherwise $.

\nnn
The character whose ASCII code is the octal value nnn.

\\
A backslash.

\[
Begin a sequence of non-printing characters. This could be used to embed a terminal control sequence into the prompt.

\]
End a sequence of non-printing characters.

We seem to find what we want color options, how to do it? I remember someone that can change the color of it! Then I thought of the .bashrc file in the home directory. Let me open look:
$cat ~/.bashrc
Then I found this passage:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ 

In this paragraph there seems to be [\ 033 [01; 32m] do not understand this, combined with a content of 01,34 These are probably not the color code? It really is! After the test, I get a command prompt color options in the following format:

开头:\[\033[F;B;Cm\]
结尾:\[\033[00m\]

Note: Why more than a C? Previous combination, we can know that there are three color settings parameters can be used here is also true. In addition, once the character appears in the back of the color options will not take effect, encountered similar output string '\ 0'.
I now PS1 variable is what it? as follows:

\033[32;40;1m\u@\h:\e[33;40m\W\033[0m$
A little different, right? A closer look at the top of that comes a large segment, which has [not provinces can (but between a "[" and "]", it is not printed, so after a test found that eliminating the color code 003 , pay attention to what you can find, it is less a backslash, not a non-printing characters).

Guess you like

Origin www.cnblogs.com/ZEROPONG/p/11843097.html