Let your shell command prompt fly up ~

Source: Internet
Author: User

Some time ago, just came to practice, because their development machine environment has not yet been equipped with the boss of the machine, opened, Yi ~! Why not traditional linux [[email protected]]? This aroused the baby's great curiosity (why the tender?) Do you want to pretend to be old? And, as a result, once again opened the bird Brother's recipe (bird brother's Linux private dishes), but also for the sake of the Niang, finally have the answer.

ps1! Yes, that's what this is called PS1, open Linux, enter commands .

echo $PS 1

That's what you see.

Echo

This is the PS1 of your linux shell command Prompt!

What does this PS1 mean? After Baidu got the answer:

\d: Represents the date, formatted as weekday month date, for example:"Mon-1"

\h: The full host name. For example: My machine name is:Fc4.linux, then this name is fc4.linux

\h: Take the first name of the host only, as in the example above, then FC4,. Linux is omitted

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

\ t: Display time in 12-hour format

\a: Display time in 24-hour format:HH:MM

\u: Current user's account name

\v:version information for bash

\w: The full working directory name. Home directory will be replaced by ~

\w: Use basename to get the working directory name, so only the last directory is listed

\#: The first few commands issued

\$: Prompt character, if root, Prompt is:#, Normal user is:$

But why are the different places on the boss's machine not the same color? Don't worry, we look down:

We can make the prompt into color by setting the PS1 variable. The format for setting the character sequence color in PS1 is:\[\e[f; Bm\] where "F" is the font color, number 30~37; "B" is the background color, number 40~47. However, can set the color, he will certainly be able to cancel the settings, note: Here the cancellation settings, and not set is two things! As for the detailed distinction, when you have finished reading my post you are O. Oh. Cancel setting:\[\e[m\]

Color table

Foreground background color

30 40 Black

31 41 Red

32 42 Green

33 43 Yellow

34 44 Blue

35 45 Purplish red

36 46 Cyan Blue

37 47 White

Code meaning

0 OFF

1 highlighting

4 Underline

7 Anti-white display

8 Not visible

Let me give you an example.

Open our. bashrc file

Vim ~/.BASHRC

Add a row inside

Export ps1="[\[\e[32m\]#\##\[\e[31m\]\[email protected]\[\e[36m\]\h \w]\$\[\e[m\]"

Then, save and execute with Source:

SOURCE ~/.BASHRC

Now look at \[\e[32m\], this part is used to set the color, these several characters combined with the above description, it may be seen here is set to green. The next \[\e[32m\] is set to red ... And the last \[\e[m\] is to tell Linux, the future content does not need color ~ Use the default color is good. Then #\# #就是显示现在运行的是第几条命令了, see. I'm here in fourth one.[#4 #[email protected]localhost ~]$ down is \u, that's what it means? I look at the table, and then not another set in color (not shown here), \h \w mean? \h is said: Only the first name of the host, \w is said: Show the full path, if the user's default path is displayed ~, the rest of the situation is to show the full path of OH. The front [and last] is the one you see that is the outermost enclosing bracket. Understand it ~ But a lot of children's shoes and have doubts, this is only set the color and style, usually a lot of children's shoes in the development of the use of Git, then at the command prompt if there is git state display is not perfect? Yes, let's talk about how to show git status. After the blogger's search, finally got a set of methods: That is, add the following in the. bashrc file:
functionParse_git_dirty {[[$ (Git status2>/dev/NULL|Tail-N1)! ="Nothing -to-commit (working directory clean)"]] &&Echo "*"}functionparse_git_branch {git branch--no-color2>/dev/NULL|sed-E'/^[^*]/d'-E"s/* \ (. *\)/git:\1$ (parse_git_dirty)/"}export PS1="\[\e[36m\]0\[\e[33m\]\$ (parse_git_branch) \[\e[m\] \w \[\e[36m\]\t\[\e[m\]\n\[\e[35m\]→\[\e[m\]"
The concrete meaning everybody crossing oneself ponder! The effect is first not show ha ~ Of course, the use of zsh will have a better effect, bloggers will share in the next week ~ please look forward to. This article refers to: Brother Bird's Linux private cuisine http://blog.sina.com.cn/s/blog_6268defa0100wijx.html

Let your shell command prompt fly up ~

Related Article

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.