0

This is my ConsoleZ powershell that I wanted to have a posh-git environment also, but doesn't work.

ConsoleZ power-shell

This line of code is inside the Microsoft PowerShell profile

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

I have been trying a couple of time now, posh-git won't integrate on to my consoleZ.

The problem is it won't run posh-git after putting all the scripts needed in the $profile.

I can't get it to be like this.

Example consoleZ with posh-git running

UPDATE

Burt_Harris comment was right, it was because of the prompt function that was messing with posh_git, now my problem is how to get the 2 functions working?

UPDATE 2

My script to combine the two prompt functions. just give me PS> instead of folder directory>

# 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)"
}

SOLUTION

Instead of using this

Write-Host($pwd.ProviderPath) -nonewline

on the posh_git example profile, I modified it to

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

that did the trick, didn't need to make another function.

juscuizon
  • 51
  • 1
  • 9
  • My question is what is wrong with the script i have for my $profile. I can't seem to get posh-git running with consoleZ. The git environment works with consoleZ but posh-git doesn't display on consoleZ. – juscuizon Sep 15 '16 at 00:07
  • Perhaps posh-git (which I've never used) operates by replacing the prompt function, and your script replaces it's prompt function with it's own. Try putting `function prompt` at the beginning of your script. – Burt_Harris Sep 15 '16 at 22:18
  • @Burt_Harris completely right, do you know how to make the two prompt function work at the same time? any suggestions. – juscuizon Sep 16 '16 at 22:29

2 Answers2

0

Save away the old prompt function and call it in your overridden version, concatenating the different information together. For example:

$previousPrompt = $function:prompt

function prompt() { 
    "MyPrompt`n$(&$previousPrompt)"
    }
Burt_Harris
  • 6,415
  • 2
  • 29
  • 64
0

Instead of using this

Write-Host($pwd.ProviderPath) -nonewline

on the posh_git example profile, I modified it to

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

that did the trick, didn't need to make another function.

juscuizon
  • 51
  • 1
  • 9