【问题标题】:powershell script to show git info and just the working directory用于显示 git 信息和工作目录的 powershell 脚本
【发布时间】:2014-10-08 18:37:10
【问题描述】:

我已经做了一些谷歌搜索,但还没有找到解决方案,所以我希望在这里得到一些帮助。

我已经安装了 posh-git 以与 powershell 一起使用,并希望保留它添加到提示行的 git 状态,但我不希望打印整个工作目录,因为它很烦人。我只想要当前文件夹。我找到了代码来做每一个,但不知道如何组合它们。

默认的 posh-git 打印路径和 git 信息是

function global:prompt {
$realLASTEXITCODE = $LASTEXITCODE

# Reset color, which can be messed up by Enable-GitColors
$Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

Write-Host($pwd.ProviderPath) -nonewline

Write-VcsStatus

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

仅打印路径中当前文件夹的代码是

function prompt { 
'PS ' + ($pwd -split '\\')[0]+' '+$(($pwd -split '\\')[-1] -join '\') + '> '
}

我尝试了两者的各种混搭,但还没有弄清楚如何让它做我想要的。

这里有一张图片来帮助说明

任何帮助都会很棒,谢谢:)

【问题讨论】:

  • 那么不打印$pwd.ProviderPath

标签: powershell


【解决方案1】:

不是打印$pwd.ProviderPath,而是打印Split-Path -Leaf

function global:prompt {
    $realLASTEXITCODE = $LASTEXITCODE

    # Reset color, which can be messed up by Enable-GitColors
    $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

    Write-Host(Split-Path -Leaf $pwd.ProviderPath) -nonewline

    Write-VcsStatus

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

【讨论】:

    猜你喜欢
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    • 2011-11-03
    • 2014-04-23
    • 1970-01-01
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多