Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Posh Git Won't Show Status or Colors on Prompt (Win 7) #161

Closed
ghost opened this issue Nov 9, 2014 · 7 comments
Closed

Posh Git Won't Show Status or Colors on Prompt (Win 7) #161

ghost opened this issue Nov 9, 2014 · 7 comments

Comments

@ghost
Copy link

ghost commented Nov 9, 2014

(Posted this on Stack Overflow and got a suggestion to leave it here) -
http://stackoverflow.com/questions/26812896/posh-git-wont-show-status-or-colors-on-prompt?noredirect=1#comment42200920_26812896

I'm on Windows 7, installed git and then posh-git (to run git from powershell), no errors. I'm able to enter git commands like 'git init' and 'git status' now from the powershell, and posh-git's tab completion works in my powershell, so I believe means posh-git was installed successfully.

However, according to posh-git documentation, my powershell prompt should now provide 'git status' info with colors (like [master] when my directory has a .git file), but it doesn't. I ran $GitPromptSettings (which I found on posh-git's github readme) but "EnablePromptStatus" is True, and I don't see any other options in the GitPromptSettings that it looks like I should change to enable the prompt status.

My current directory in powershell has a .git folder in it, from a 'git init' command I entered in powershell, so I can't figure out why posh-git's PromptStatus feature isn't reflected in my powershell prompt.

@keystroke
Copy link

Hello, what do you see when you type "$Function:prompt" into the PowerShell terminal? This should return the contents of the function that is run to generate the prompt.

The next thing to verify is that your profile contains a call to declare this function prompt. Type "notepad $profile" to view and edit the contents of this file.

Also note that you actually have two profiles - one for when you run PowerShell from the terminal, and another for when you run ISE. Verify that your profile contains a call that looks something like the below:

# Load posh-git example profile
. '<path to your git repo>\posh-git\profile.example.ps1'

Also verify that the contents of the file shown above contain code like the following (you can customize this to suit your personal preference):

Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

# Load posh-git module from current directory
Import-Module .\posh-git

# If module is installed in a default location ($env:PSModulePath),
# use this instead (see about_Modules for more information):
# Import-Module posh-git


# Set up a simple prompt, adding the git prompt parts inside git repos
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 "> "
}

Enable-GitColors

Pop-Location

Start-SshAgent -Quiet

@dahlbyk
Copy link
Owner

dahlbyk commented Nov 13, 2014

Also, do you see anything in $Error?

@ghost
Copy link
Author

ghost commented Nov 13, 2014

Hey, sorry for the slow response. I'm at work now so can't test this out
(my issue and git/python are on my home computer for a side project) but
will try these out soon and get back to you. Thanks for the help!

Max

On Thu, Nov 13, 2014 at 8:41 AM, Keith Dahlby [email protected]
wrote:

Also, do you see anything in $Error?


Reply to this email directly or view it on GitHub
#161 (comment).

@ghost
Copy link
Author

ghost commented Nov 17, 2014

Hi, thanks again for reviewing this issue, and for maintaining poshgit!

So, when I type $Error into powershell (shell not ISE), nothing outputs (just back to >).

When I typed "$Function:prompt, I got the following response:
PS C:\users\max\desktop\git_practice> $Function:prompt
"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

.Link

http://go.microsoft.com/fwlink/?LinkID=225750

.ExternalHelp System.Management.Automation.dll-help.xml

And finally, when I typed notepad $profile, a notepad file called PowerShell_profile.ps1 opened, but it was actually totally blank. So I should have to add text to that whenever I create a new git init? Or should poshgit update my powershell profile automatically?

My execution policy is remote-signed, so I don't think I should be preventing undue changes to my profile in general. Should I re-install posh-git with an unrestricted execution policy?

Thanks,
Max

@dahlbyk
Copy link
Owner

dahlbyk commented Nov 21, 2014

Your prompt looks like posh-git isn't being loaded at all, which is what I would expect if your PowerShell_profile.ps1 is empty.

I would try running posh-git's install.ps1 again. If your remote-signed execution policy allows that script to run, the module itself should load just fine.

@baz-sh
Copy link

baz-sh commented Apr 20, 2015

I was having this issue also in powershell; Note my solution is almost identitcal to dahlbyk's. Although to allow certain git commands you need the line
$env:TERM="msys"

Additionally if your like me then you don't want the preceding *.* that is on the posh-git import line

So, in C:\users\documents\ YOURUSERNAME \WindowsPowershell\

edit with notepad: Microsoft.PowerShell_profile1.ps1

Copy / Paste:

$env:TERM="msys"
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

# Load posh-git module from default directory
Import-Module posh-git

# Set up a simple prompt, adding the git prompt parts inside git repos
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 "> "
}

Enable-GitColors

Pop-Location

Start-SshAgent -Quiet

Save this file then restart powershell and you'll be good to go.

@rkeithhill
Copy link
Collaborator

I believe this has been addressed with PR #349. @dahlbyk Do you concur that we can close this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants