Powershell turns black on running command

Viewed 186

My original Powershell with a blue background looks quite good and easy to work with.:

Original Terminal

However on running certain commands like conda or code, it turns black, something like this: Terminal After running command

Can anyone please tell me how to fix it?

1 Answers

Try adding this to your profile. And repeat and adapt for any other commands that have the same issue.

Some commands will alter the foreground, or background color. This should reset them. $args is a special variable that will contain everything after you type the function. It should function just like running the old command (which is (probably) really conda.exe). The try/finally is to make sure it always resets the colors, even if the program crashes or you press Ctrl-C

Function conda {
    $fg = [console]::ForegroundColor
    $bg = [console]::BackgroundColor
    try {
        conda.exe $args
    } finally {
        [console]::ForegroundColor = $fg
        [console]::BackgroundColor = $bg
    }
}

To find your profile run this:

$profile

If the file does not exist, create it, and add the above code.

Edit: Remember that after updating your profile, you need to either restart Powershell, or source your profile like this:

. $profile
Related