views:

47

answers:

1

If I use write-host to define my prompt, Powershell adds "PS>" automatically at the end. How can I use write-host so that it doesn't do that?

function prompt {
    '> '
}

#prompt:
#>

function prompt {
    write-host '> ' -foregroundcolor "green"
}

#prompt:
#>
#PS>
A: 

Solved; do this:

function prompt {
    write-host '>' -foregroundcolor "green" -nonewline
    ' '
}

#prompt:
#>
guillermooo
function prompt is expected to return a prompt string. When you use Write-Host you are bypassing the return value and writing directly to the host. If PowerShell observes that the prompt function doesn't return anything or an empty string, it uses a default prompt. As you have discovered returning any non-empty string will cause PowerShell to use that string instead of the default prompt.
Keith Hill