2014-10-08 55 views
0

我做了一些谷歌搜索,沒有找到一個解決方案,所以我希望在這裏得到一些幫助。powershell腳本來顯示git信息,只是工作目錄

我安裝了posh-git與powershell一起使用,並且希望保持它添加到提示行的git狀態,但是我不希望打印整個工作目錄,因爲它很煩人。我只想要當前的文件夾。我找到了每個代碼,但不知道如何組合它們。

默認豪華-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 '\') + '> ' 
} 

香港專業教育學院嘗試都和還沒有的各種mishmashes想出瞭如何讓它做我想做的事。

繼承人PIC幫助說明

enter image description here

任何幫助將是巨大的,謝謝:)

+0

不要那麼打印'$ pwd.ProviderPath'? – 2014-10-08 18:42:54

回答

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 "> " 
} 
+0

非常感謝你! – 2014-10-08 19:29:36