Sets the command line prompt

The command line prompt displays the user name, current machine IP, current time, current path and other information. But sometimes if we have a long directory and it’s inconvenient to type a command, we can modify the PS1 environment variable to make the command prompt appear on the second line:

As shown in the following example, the \n prompt is displayed on the second line.

export PS1="\[\033[01;31m\]\u\[\033[00m\]@\[\033[01;32m\]\h\[\033[00m\][\[\033[01;33m\]\t\[\033[00m\]]:\[\033[01;34m\]\w\[\033[00m\ ]\n$ "
Copy the code

The effect is as follows:

Note:

Set why color, you can adjust according to the display effect, very flexible.

advice

If you want to write shell configuration files, it is recommended to write ~/. Bash_profile instead of ~/. Bashrc. Otherwise, SSH tools such as SCP /rsync will wait indefinitely due to the particularity of trap DEBUG signals.

If yes, set it; otherwise, do not set it:

if [ "${-#*i}"! ="$-" ];then
    # interactively shell
    PS1="\[\033[01;31m\]\u\[\033[00m\]@\[\033[01;32m\]\h\[\033[00m\][\[\033[01;33m\]\t\[\033[00m\]]:\[\033[01;34m\]\w\[\033[00m\ ]\n$ "
    trap 'echo -ne "\e[0m"' DEBUG
fi
Copy the code
# write
vim ~/.bash_profile

# Effective immediately
source ~/.bash_profile
Copy the code

Parameters that

The command prompt displayed on the terminal: [root@root ~]#

PS1=”[\u@\h \W]\$”

  • Set the prompt format:PS1

The definitions of the common parameters in PS1 are as follows:

\d: # stands for weekday month date, for example: “Mon Aug 1”

\H: # Full host name

\h: # Take only the first name of the host

\T: # Display time in 24-hour format, such as HH: MM: SS

\ T: # Display time in 12-hour format, e.g. HH: MM: SS

\A: # Display time is 12 hours format: HH: MM

\u: # The account name of the current user

\ V: version information for #BASH

\ W: # Full working directory name

\W: # Use basename to get the working directory name, so only the last directory will be listed

The number of commands given

$: # Prompt character. If the user is root, the prompt is #. If the user is common, the prompt is $

Set the color

In PS1, set the character color format as: [\e[F;Bm], where F is the font color and the number is 30-37, and B is the background color and the number is 40-47.

The color table is as follows:

[\e[F;Bm] Part that needs to change color [\e[0m]

Start color input: [\e[F;Bm]

End color input: [\e[0m]

  • The colors of the F and B values
30 40 black 31 41 red 32 42 green 33 43 yellow 34 44 blue 35 45 Fuchsia 36 46 turquoise blue 37 47 WhiteCopy the code
  • Setting special display
0 OFF: Disables the color. 1 Highlight 4 Underline 5 Blink 7 Reverse white 8 Color is invisibleCopy the code

Special display can be set in the end color input: [\e[special color number m]

Other color matching configurations

Click the following button at the top of the Xshell panel.

Click the Browse button to bring up the following panel, select ANSI Colors on Black, then click the Save as button on the right and name it ZKL.

This is simply a copy of the ANSI Colors on Black color scheme, or we can create a New one.

ANSI colors are already pretty good, here we use ANSI colors and modify them to get the color scheme we want.

Then, click the Edit button on the right to edit the foreground and background colors.

1. Set the background color

Click the drop-down list on the right of Backgroud, select Other in the popup interface, an interface will pop up, click Custom color, and the following interface will pop up:

Fill in the color according to the following RGB values, (0,43, 53)

Then click the Add to Custom Colors button, Add the Custom Colors in the left pane under Custom Colors, and select it. Sure.

2. Set font color (foreground color)

Click Normal Text to set it up.

RGB color :(131,148,150)

3. Set the directory color

Color RGB values are as follows :(128,128, 255)

4. Set the color of the compressed file

In ANSI color, the color of compressed files is red by default, which does not disturb sight. If you feel bad, you can change it to the following color:

Color RGB values are as follows :(128,128, 0)

5. Set the color of comments in VIM

After the above Settings, xshell background color, font color, Linux directory, compressed file color are better, the effect is as follows.

But when we open vim and edit a c++, python code file, the color of the comments is not very nice. You need to set it again.

Set the following colors:

RGB color :(255,128,64)

The modified code file displays as follows:

6. Export the color scheme

Xshell is very powerful with all kinds of functions. The color scheme we set up can also be exported and saved, and can be imported when we use it on other machines.

Import and export in the following interface can import and export the color scheme. The following file is the color scheme file corresponding to the above configuration: