Linux terminal command line prompt art-PS1 advanced

Source: Internet
Author: User

If you don't want to talk about it, first glance at my command line prompt (a little big ):

The command line in the figure is as follows:
Calendar [date of the Gregorian calendar/date of the lunar calendar]
Else [number of directories under the current directory + number of items below the current directory] [current absolute Directory]
Users [username @ host name-the number of terminals required _ hosts]

Related configuration files

Global configuration file:/etc/bash. bashrc or/ect/bashrc

Single-user configuration file: "~" . Bashrc files in the directory

Code

The code corresponding to this parameter is as follows (generally, the original PS1 is overwritten by the Add location, which can be modified on the original PS1 or directly added to the end of the configuration file ):

=$( +%=$( -R |  -c - | =$(lunar ` +%Y\ %m\ %d` |  |  | =$( -l |  ^d |  -l);fn=$( $( |  -l) -=$( $Lunar| - =  ] && space=  =  ] && space=  =\\\[\[\e[;34m\]${dn}\[\e[00m\]+${fn}][\[\e[;34m\]\\\[${debian_chroot:+($debian_chroot)}\[\e[;32m\]\u@\h-\l \[\e[00m\]\\\\\\\]\$=get_ps1

If you think the above command line prompt is too complicated, you can also reduce it...

What you need to know

If you want to design a command line prompt that you like and is dazzling enough, you should first understand the following.

1) The Lunar date is involved, which can be found in the source in Ubuntu 12.04 LTS.LunarSoftware package, but not in Fedora and CentOS. For this reason, I wrote a shell script for converting the Gregorian calendar to the lunar calendar. For details, see my.

2) escape characters and colors. I am no longer arrogant about this. google's "Linux Command Line color" will have a lot of answers.

3) PROMPT_COMMAND: This is the key to real-time command line. The content of this variable will be executed before the bash prompt is displayed, so the real-time content used above needs it.

4) What should I do if special characters cannot be displayed? You can convert it to character encoding. You can escape it. In the Plain text column, enter the character you want to escape. In the \ OOO column, it is the character encoding you want.

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.