PowerShell 中不显示 git 状态提示

问题描述 投票:0回答:1
function prompt {
    $time = Get-Date -Format "HH:mm"
    $location = (Get-Location -PSProvider FileSystem).Path

    $promptText = "["
    $promptText += "$([char]27)[96m$time$([char]27)[0m "
    $promptText += "$([char]27)[32momkrbhagat$([char]27)[0m "
    $promptText += "$([char]27)[35m$location$([char]27)[0m"

    Write-Host $promptText -NoNewline
    return " ~ "
}

这是我自己的 PowerShell 自定义提示。我也在我的 $PROFILE 中安装了 posh-git 并导入了模块。 Git 命令选项卡完成功能也运行良好,但当我初始化 git 存储库时,没有看到 Git 状态提示。 我认为我自己的自定义提示会影响显示 Git 状态提示。那么,如何整合自己的提示符和 Git 状态提示符呢?

我期望以下输出:

[HH:mm] omkrbhagat C:\Users\onkar (master) ~ 

为此,我附加以下行:

if (Test-Path variable:GitPromptSettings) { Write-VcsStatus }

但是还是没有成功。 除此之外,只有当我初始化 git 存储库时,才会显示 git 状态提示。

powershell customization prompt posh-git oh-my-posh
1个回答
0
投票

检查此文件“about_posh-git.help.txt”。

如果您想精细控制 Git 状态摘要信息在提示功能中的显示方式,您可以通过

Get-GitStatus
命令获取原始状态摘要信息。然后您可以根据需要在提示中显示信息。

© www.soinside.com 2019 - 2024. All rights reserved.