I like to define the env variable PROMPT as $p$_$g so prompt starts in a new line.

But seems to be not applying to my PowerShell prompt :-(

dir function:/ shows that a name "prompt" is already defined.

Any way I can get my prompt customized in a PowerShell console, without messing up with the already defined "prompt" name?

link|improve this question

27% accept rate
feedback

1 Answer

up vote 9 down vote accepted

The prompt function is just the default prompt supplied by Powershell. If you put a new prompt function into your profile, it will overwrite the existing one - but if you remove the custom definition in your profile, the previous function will be used again.

Edit your profile with:

notepad $profile

Then add your custom prompt function:

function prompt {
    "$pwd
    >"
}

Restart powershell and you will have your new prompt.

To revert, just edit $profile again and remove the new function.

link|improve this answer
A note to add: You can do pretty much anything in your prompt function, including colorized output (with Write-Host), &c. However, keep in mind that it must return something. If you only do Write-Host -Fore Green -no "PS $pwd> " in there you'll get a prompt like PS Home:\> PS> since PowerShell assumes that an empty prompt wasn't what you meant. In those cases you can output a character more than needed and return "b"` (the backspace character). – Joey May 30 '10 at 9:34
Johannes: can't believe I forgot about $pwd, thanks! – MattB May 30 '10 at 13:48
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.