Powershell在运行命令时变黑

标签 powershell terminal windows-10

我原来的蓝色背景的 Powershell 看起来相当不错并且易于使用。:

Original Terminal

但是,在运行某些命令(例如 condacode)时,它会变成黑色,如下所示: Terminal After running command

谁能告诉我如何解决这个问题吗?

最佳答案

尝试将其添加到您的个人资料中。并对具有相同问题的任何其他命令进行重复和调整。

某些命令会改变前景色或背景色。这应该重置它们。 $args 是一个特殊变量,它将包含您键入函数后的所有内容。它的功能应该就像运行旧命令一样((可能)实际上是 conda.exe)。 try/finally 是为了确保它始终重置颜色,即使程序崩溃或您按 Ctrl-C

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

要查找您的个人资料,请运行以下命令:

$profile

如果该文件不存在,则创建它,并添加上述代码。

编辑:请记住,更新您的个人资料后,您需要重新启动 Powershell,或按如下方式获取您的个人资料:

. $profile

关于Powershell在运行命令时变黑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62467223/

相关文章:

powershell - Powershell ConvertTo-CSV自定义 header

php - 如何在 Windows 笔记本电脑上本地设置 PHPUnit?

command-line - 为什么我的命令提示符在 Windows 10 上卡住?

mysql - 从 MSSQL Windows10 查询 MYSQL 数据库

java - Selenium -Java : Microsoft Edge automation browser (Windows 10)

找不到 powershell -Scope 参数

email - 发送邮件消息 : The SMTP server requires a secure connection or the client was not authenticated.

c++ - clang 编译器无法在 Mac OSX 终端上运行

linux - zsh提示功能不起作用

powershell - powershell版本号比较