结合PowerShell提示功能(例如ConsoleZ和posh-git)

时间:2016-09-14 13:49:26

标签: git powershell posh-git

这是我的ConsoleZ powershell,我也希望有一个豪华环境,但是不起作用。

ConsoleZ power-shell

此代码行位于Microsoft PowerShell配置文件

Write-Host "Setting up GitHub Environment"
. (Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1")

Write-Host "Setting up Posh-Git"
. (Resolve-Path "$env:github_posh_git\profile.example.ps1")



function prompt {
  $p = Split-Path -leaf -path (Get-Location)
  "$p> "
}

我现在已经尝试了几次,posh-git不会集成到我的consoleZ上。

问题是在放置$ profile中需要的所有脚本后,它不会运行posh-git。

我不能让它像这样。

Example consoleZ with posh-git running

更新

Burt_Harris评论是对的,这是因为提示函数搞乱了posh_git,现在我的问题是如何让2个函数工作?

更新2

我的脚本结合了两个提示函数。给我PS>而不是文件夹目录>

# Prompt for shortened link on command line
function myPrompt {
    $p = Split-Path -leaf -path (Get-Location)
    "$p> "
}

$myPrompt = $function:myPrompt

# Set up a simple prompt, adding the git prompt parts inside git repos
function posh_gitPrompt {
    $realLASTEXITCODE = $LASTEXITCODE
    Write-Host($pwd.ProviderPath) -nonewline
    Write-VcsStatus
    $global:LASTEXITCODE = $realLASTEXITCODE
    return "> " 
}

# Combine myPrompt & posh_gitPrompt
function global:prompt {
    "myPrompt`n$(&$posh_gitPrompt)"
}

而不是使用此

Write-Host($pwd.ProviderPath) -nonewline

在posh_git示例配置文件中,我将其修改为

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

做了这个伎俩,不需要再做一个功能了。

2 个答案:

答案 0 :(得分:0)

保存旧的提示功能并在覆盖的版本中调用它,将不同的信息连接在一起。例如:

$previousPrompt = $function:prompt

function prompt() { 
    "MyPrompt`n$(&$previousPrompt)"
    }

答案 1 :(得分:0)

而不是使用此

Write-Host($pwd.ProviderPath) -nonewline

在posh_git示例配置文件中,我将其修改为

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

做了这个伎俩,不需要再做一个功能了。