【问题标题】:Custom prompt prints twice in PowerShell Core 6.0 on Ubuntu自定义提示在 Ubuntu 上的 PowerShell Core 6.0 中打印两次
【发布时间】:2018-01-15 17:02:49
【问题描述】:

我的 $PROFILE 中有一个自定义 PowerShell 提示功能,它在 Windows 上适用于 PS 5.1 和 PS Core 6.0,但不适用于 Ubuntu 17.04 上的 PS Core 6.0。

在 Ubuntu 提示符下重复:

为了让事情变得更有趣,当我开始输入时,光标移动并且命令文本出现在我期望的位置,如果输出没有重复的话: 命令还将在重复的提示输出之上打印输出。

$PSVersionTable的输出:

Name                           Value                                                                                                                                                                                             
----                           -----                                                                                                                                                                                             
PSVersion                      6.0.0                                                                                                                                                                                             
PSEdition                      Core                                                                                                                                                                                              
GitCommitId                    v6.0.0                                                                                                                                                                                            
OS                             Linux 4.10.0-40-generic #44-Ubuntu SMP Thu Nov 9 14:49:09 UTC 2017                                                                                                                                
Platform                       Unix                                                                                                                                                                                              
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                           
PSRemotingProtocolVersion      2.3                                                                                                                                                                                               
SerializationVersion           1.1.0.1                                                                                                                                                                                           
WSManStackVersion              3.0 

生成提示的函数:

function global:prompt {
    $realLASTEXITCODE = $LASTEXITCODE

    Write-Host
    Write-Host (Get-Date -Format:'o') -ForegroundColor:DarkGray
    Write-Host "PS " -NoNewline -ForegroundColor:Green
    Write-Host $pwd.ProviderPath -NoNewline
    # Write-VcsStatus
    Write-Host

    $global:LASTEXITCODE = $realLASTEXITCODE
    return "> "
}

我是 Linux 新手,我对可能导致这种奇怪行为的原因进行的搜索到目前为止都没有结果。任何帮助将不胜感激。

【问题讨论】:

    标签: linux powershell powershell-core


    【解决方案1】:

    这是 Core 附带的 PSReadLine 版本中的一个错误。这是issue

    您可以安装 2.0 的预发布版本。

    Install-Module PSReadLine -RequiredVersion 2.0.0-beta1 -AllowPrerelease -Force
    

    如果您收到关于 -AllowPrerelease 的错误,您还需要更新 PowerShellGet

    Install-Module PowerShellGet -RequiredVersion 1.6.0 -Force
    

    【讨论】:

      猜你喜欢
      • 2013-01-02
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 2023-04-10
      相关资源
      最近更新 更多