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!