Magical _powershell of prompt function in PowerShell

Source: Internet
Author: User
Tags function definition

This article describes the prompt function in PowerShell and the prompt function to customize the prompts for the PowerShell command-line interface.

Before designing the prompt function, the small part wants to change the PowerShell command line prompt to Zhanghong> Look for it, find the prompt this function. Let's take a look at a function definition as follows:

Copy Code code as follows:

function prompt{
"PS zhanghong>"
}

This is a very ordinary function, there is no substantive difference. And the code inside the function body is very simple, directly output a string.
Put this function in the PowerShell to perform a look:
Copy Code code as follows:

PS c:\users\zhanghong> function prompt{
>> "PS zhanghong>"
>>}
>>
PS zhanghong>

Oh, my god! It's unbelievable! This function I just defined a little bit and hasn't been invoked to execute it yet! PowerShell's command prompt has been modified! Very good, very powerful Ah!

Later, the small series also found that in the PowerShell of this prompt function, can also do some interesting things. For example, I let the prompt become a fixed string, but I want to know what the current path is, can not always use PWD bar. So small make up see a cow man is so used, he put the current path to the command line window title, really invincible! In the future, regardless of what the path becomes, the title will follow the correct current path.

Copy Code code as follows:

function prompt{
"PS zhanghong>"
$host. Ui. Rawui.windowtitle = (get-location)
}

Don't believe it, try it! The prompt function only needs to be defined, no need to call Oh!

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.