Posh-Git was working great for months. Then, it suddenly stopped working; there is no posh-git prompt anymore. It's like it's not installed. I see no errors. I can even see values in $global:GitPromptSettings
I have tried uninstalling, reinstalling, upgrading (I was on 0.7.3 for months and the problem came about before I upgrade to 1.0.0).
I have installed the following in the past few days, any of which could be the culprit, just based on the timing:
Can you confirm that posh-git has been imported? Run Get-Module posh-git and post the output here. If that shows posh-git is loaded, it is likely then that some module is either defining a prompt function before posh-git is imported - in which case posh-git will not overwrite what appears to be the user's custom prompt function. Or another module is imported after posh-git and it overwrites the prompt function. We might be able to tell if you dump the prompt function def like so: Get-Command prompt | % Definition.
Ok, I fixed it but I don't really know how/why. Occasionally, my IT organization will remove my domain account from the local Administrators group. It's really nefarious because everything looks the same. I can still run programs elevated and there doesn't appear to be any restriction. I run Powershell and Visual Studio elevated and the title bar still says "Administrator." But weird things start happening, like this, which is how I (slowly) begin to realize it's happened. So, I switch over to another local admin account, re-add my domain account to the Administrators group, and sign back in on my domain account. Everything then returns to normal. My posh-git prompt is back.
ps - Thank you, @rkeithhill, for your quick response. I did run the commands you mentioned before I posted my question. I confirmed that the module was loaded and the prompt was coming from posh-git, which was why this was such a weird mystery. Here is the output (same now as it was before I made the Administrators fix):
Output of Get-Module posh-git:
Script 1.0.0 posh-git {Add-PoshGitToProfile, Expand-GitCommand, Format-GitBranch...
Output of Get-Command Prompt | % Description:
$settings = $global:GitPromptSettings
if (!$settings) {
return "<`$GitPromptSettings not found> "
}
if ($settings.DefaultPromptEnableTiming) {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
}
$origLastExitCode = $global:LASTEXITCODE
if ($settings.SetEnvColumns) {
# Set COLUMNS so git knows how wide the terminal is
$Env:COLUMNS = $Host.UI.RawUI.WindowSize.Width
}
# Construct/write the prompt text
$prompt = ''
# Write default prompt prefix
$prompt += Write-Prompt $settings.DefaultPromptPrefix.Expand()
# Get the current path - formatted correctly
$promptPath = $settings.DefaultPromptPath.Expand()
# Write the path and Git status summary information
if ($settings.DefaultPromptWriteStatusFirst) {
$prompt += Write-VcsStatus
$prompt += Write-Prompt $promptPath
}
else {
$prompt += Write-Prompt $promptPath
$prompt += Write-VcsStatus
}
# Write default prompt before suffix text
$prompt += Write-Prompt $settings.DefaultPromptBeforeSuffix.Expand()
# If stopped in the debugger, the prompt needs to indicate that by writing default propmt debug
if ((Test-Path Variable:/PSDebugContext) -or [runspace]::DefaultRunspace.Debugger.InBreakpoint) {
$prompt += Write-Prompt $settings.DefaultPromptDebug.Expand()
}
# Get the prompt suffix text
$promptSuffix = $settings.DefaultPromptSuffix.Expand()
# When using Write-Host, we return a single space from this function to prevent PowerShell from displaying "PS>"
# So to avoid two spaces at the end of the suffix, remove one here if it exists
if (!$settings.AnsiConsole -and $promptSuffix.Text.EndsWith(' ')) {
$promptSuffix.Text = $promptSuffix.Text.Substring(0, $promptSuffix.Text.Length - 1)
}
# This has to be *after* the call to Write-VcsStatus, which populates $global:GitStatus
Set-WindowTitle $global:GitStatus $IsAdmin
# If prompt timing enabled, write elapsed milliseconds
if ($settings.DefaultPromptEnableTiming) {
$timingInfo = [PoshGitTextSpan]::new($settings.DefaultPromptTimingFormat)
$sw.Stop()
$timingInfo.Text = $timingInfo.Text -f $sw.ElapsedMilliseconds
$prompt += Write-Prompt $timingInfo
}
$prompt += Write-Prompt $promptSuffix
# When using Write-Host, return at least a space to avoid "PS>" being unexpectedly displayed
if (!$settings.AnsiConsole) {
$prompt += " "
}
else {
# If using ANSI, set this global to help debug ANSI issues
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssigments', '')]
$global:PoshGitLastPrompt = EscapeAnsiString $prompt
}
$global:LASTEXITCODE = $origLastExitCode
$prompt
Glad you got it figured out. Yeah, your output indicates that it should be displaying the posh-git prompt. OK to close this issue then?
Hi, I have the same issue and I even know what caused it, but I can't figure out how to fix it. Can someone help me?
My system is Windows 10, posh-git was working fine until I initialized conda (python package distribution software provided by Anaconda) via conda init powershell, which made some modifications to the system. Now the git status info is not displayed in the prompt. Running Get-Command prompt gives:
CommandType Name Version Source
----------- ---- ------- ------
Function prompt 0.0 Conda
I guess, prompt settings were overridden by conda. Is there a chance to fix it and make both posh-git and conda prompts work together? I decided to first ask here hoping that there is a quick fix. If not, I'll open an issue in the conda repo.
@evfro This was just reported the other day for conda. See https://github.com/dahlbyk/posh-git/issues/765 for fix.
@evfro The main issue you are facing here is because Conda will initialize first so that it can activate your environments. This makes some changes to the PowerShell Prompt. post-git will not make any changes if it sees that the Prompt is already customized. So to solve this, open your PowerShell $PROFILE and in that add Import-Module posh-git at the top of the file. Moreover, any other posh-git customization you may have (like colors or date) add them all after the import module line but _before_ the Conda code. So, just add all you posh git stuff before Conda does anything to the Prompt.
@dahlbyk @arafat-ar13 thank you very much for the help and explanations! It's all clear now. I have fixed the problem. Actually, I prefer not to have conda initialized by default, so I removed it from $PROFILE. I then created a special profile dedicated to my conda environment in the Windows Terminal. The settings look like:
"commandline" : "pwsh.exe -ExecutionPolicy ByPass -NoExit -Command (C:/Users/user/Anaconda3/Scripts/conda.exe shell.powershell hook) | Out-String | Invoke-Expression ; (conda activate my_env)",
When I need it I just open a new tab in the terminal using this profile. This way I have more control over which environmental variables are available.
Most helpful comment
@dahlbyk @arafat-ar13 thank you very much for the help and explanations! It's all clear now. I have fixed the problem. Actually, I prefer not to have
condainitialized by default, so I removed it from$PROFILE. I then created a special profile dedicated to mycondaenvironment in theWindows Terminal. The settings look like:When I need it I just open a new tab in the terminal using this profile. This way I have more control over which environmental variables are available.