posh-git icon indicating copy to clipboard operation
posh-git copied to clipboard

Importing posh-git messes up the PowerShell layout

Open JesseDeBruijne opened this issue 2 years ago • 7 comments

System Details

  • posh-git version/path: 1.1.0
  • PowerShell version: 5.1
  • Git version: 2.35.1.windows.2
  • Operating system name and version: Windows 10

Issue Description

I'm importing the posh-git module in my profile, but it messes up the layout of my prompt. If I comment out the following:

Import-Module posh-git

from my profile, my powershell looks as expected. However if I leave it in, it looks like this:

image

What's going wrong here?

JesseDeBruijne avatar Jun 20 '22 08:06 JesseDeBruijne

It's hard to say without knowing more about how your profile is set up. Try this: powershell.exe -NoProfile which will start PowerShell without executing any profile script. Once PowerShell starts up, is the prompt still messed up? If it is, try executing this in that console: Import-Module posh-git; $global:GitPromptSettings.AnsiConsole = $false to see if that fixes the prompt.

rkeithhill avatar Jun 20 '22 17:06 rkeithhill

It's hard to say without knowing more about how your profile is set up. Try this: powershell.exe -NoProfile which will start PowerShell without executing any profile script. Once PowerShell starts up, is the prompt still messed up? If it is, try executing this in that console: Import-Module posh-git; $global:GitPromptSettings.AnsiConsole = $false to see if that fixes the prompt.

When I run that, PowerShell loads as expected: image

Even when I load the rest of my profile it looks as expected, only the Import-Module posh-git line seems to make it weird.

JesseDeBruijne avatar Jun 22 '22 13:06 JesseDeBruijne

When you import the posh-git module, it will install a prompt function that displays Git info when you're CD'd into a Git repo e.g.:

image

It appears that your console is not set up to support ANSI VT sequences, which posh-git uses if it detects that they're supported i.e. if $host.UI.SupportsVirtualTerminal returns True. What console are you using? The Windows default console, Windows Terminal, ConEmu, Cmder, ??

BTW by setting $global:GitPromptSettings.AnsiConsole = $false after you execute Import-Module posh-git in your profile script, you're telling posh-git to ignore the result of $host.UI.SupportsVirtualTerminal and NOT use VT sequences for coloring text.

Assuming PS indicates that it does support VT sequences, try this:

"$([char]27)[32mThis should be Green$([char]27)[0m"

Does that display the text in Green?

rkeithhill avatar Jun 22 '22 16:06 rkeithhill

When you import the posh-git module, it will install a prompt function that displays Git info when you're CD'd into a Git repo e.g.:

image

It appears that your console is not set up to support ANSI VT sequences, which posh-git uses if it detects that they're supported i.e. if $host.UI.SupportsVirtualTerminal returns True. What console are you using? The Windows default console, Windows Terminal, ConEmu, Cmder, ??

BTW by setting $global:GitPromptSettings.AnsiConsole = $false after you execute Import-Module posh-git in your profile script, you're telling posh-git to ignore the result of $host.UI.SupportsVirtualTerminal and NOT use VT sequences for coloring text.

Assuming PS indicates that it does support VT sequences, try this:

"$([char]27)[32mThis should be Green$([char]27)[0m"

Does that display the text in Green?

I've tested this with both the Windows Terminal and the default Powershell. Both display the same behavior.

Adding the line $global:GitPromptSettings.AnsiConsole = $false does solve the problem, so thanks for that! When I run the other line, it does display as green, both with and without importing posh-git and applying the other line: image

Edit; just read that you already suggested that in the previous comment, my bad haha

JesseDeBruijne avatar Jun 23 '22 09:06 JesseDeBruijne

My guess is that there is something else in one of your profile scripts that is interfering with posh-git. Can you post the output of the following command? This will show the contents of all your profile scripts.

$profile.psobject.Properties.Value | 
    Where-Object {Test-Path $_} | 
    Foreach-Object {"$('-'*78)`nContents of ${_}:`n$(Get-Content $_ -ea ignore)`n$('-'*78)"}

rkeithhill avatar Jun 27 '22 00:06 rkeithhill

By the way I had this same problem on MacOS. It started when I updated posh-git to 1.1 from 1.0. Afterwards my prompt looked like this: Text: ""Text: "", ANSI: "e[93me[39m"Text: "~"Text: "", ANSI: "e[93me[39m"Text: ""Text: ">

The problem was that my profile.ps1 file still imported the 1.0.0 version. Updating it to import 1.1.0 corrected the issue.

ALuckyGuy avatar Aug 22 '22 13:08 ALuckyGuy

$global:GitPromptSettings.AnsiConsole = $false

Same issue and this works for me

LoSealL avatar Nov 07 '22 02:11 LoSealL