Jaykul / PowerLine

A more PowerShell prompt
MIT License
567 stars 31 forks source link

Git commands causing powerline failure #12

Closed keawade closed 7 years ago

keawade commented 7 years ago

Every time I run the commands git clone, git pull, or git push my terminal's output get's turned into what look like the underlying character codes.

powershell_powerline_git_failure

I'm using HyperTerm but have verified that this occurs even in regular PowerShell.

powershell_powerline_git_failure_ps

My PowerLine config is just a slightly modified version of the demo in the Readme:

# PowerLine
#requires -Module @{ModuleName="PSGit"; ModuleVersion="2.0.4"}, @{ModuleName="PowerLine"; ModuleVersion="2.0.0"}
using module PowerLine
using namespace PowerLine

$PowerLinePrompt = 0,
(
  @(
    @{ bg = "Blue";     fg = "White"; text = { $env:USERNAME } }
    @{ bg = "Cyan";     fg = "White"; text = { $PWD } }
    @{ bg = "Cyan";     fg = "White"; text = { if($pushd = (Get-Location -Stack).count) { "$([char]187)" + $pushd } } }
    # PSGit is still in early stages, but it has PowerLine support
    @{ text = { Get-GitStatusPowerline } }
  ),
  @(
    @{ text = { New-PowerLineBlock (Get-Elapsed) -ErrorBackgroundColor DarkRed -ErrorForegroundColor White -ForegroundColor Black -BackgroundColor DarkGray } }
    @{ bg = "Gray";     fg = "Black"; text = { Get-Date -f "T" } }
  )
),
@(
  @{ text = { New-PowerLineBlock ("PS") -ErrorBackgroundColor DarkRed -ErrorForegroundColor White -ForegroundColor White -BackgroundColor Green } }
)

Set-PowerLinePrompt -CurrentDirectory -PowerlineFont:(!$SafeCharacters) -Title { "PowerShell - {0} ({1})" -f (Convert-Path $pwd),  $pwd.Provider.Name }

# As a bonus, here are the settings I use for my PSGit prompt:
Set-GitPromptSettings -SeparatorText '' -BeforeText '' -BeforeChangesText '' -AfterChangesText '' -AfterNoChangesText '' `
                      -BranchText "$([PowerLine.Prompt]::Branch) " -BranchForeground White -BranchBackground Cyan `
                      -BehindByText '▼' -BehindByForeground White -BehindByBackground DarkCyan `
                      -AheadByText '▲' -AheadByForeground White -AheadByBackground DarkCyan `
                      -StagedChangesForeground White -StagedChangesBackground DarkBlue `
                      -UnStagedChangesForeground White -UnStagedChangesBackground Blue

I'm using the font Fira Code to provide PowerLine support and ligatures.

Jaykul commented 7 years ago

Yeah. A few people have reported this. I'm seeing it now in the VS Code integrated terminal (but nowhere else). It's due to this bug: https://github.com/PowerShell/PowerShell/issues/1177

The workaround (since that fix is only in PowerShell 6.0 as far as I know) would be to call the API to set the console mode such as posh-git added here https://github.com/dahlbyk/posh-git/blob/24-bit-color/src/ConsoleMode.ps1

But I'm not sure we want everyone to call that, we'll could end up needlessly setting the ConsoleMode or four times just in the prompt function...

keawade commented 7 years ago

Okay, I tried just using the PowerShell 6 Alpha 17 (This solved the gibberish issue) but it isn't loading either $env:USERPROFILE/Documents/WindowsPowerShell/Profile.ps1 or $env:USERPROFILE/Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1 when it starts.

I can't seem to find documentation of any profile location changes either. I was able to get my profile partially working by manually executing the script and verified that this solves the gibberish problem. However, most of my custom stuff isn't working since it isn't being loaded as a profile.

keawade commented 7 years ago

I tracked down the new profile location for PowerShell 6. For anyone else attempting this fix, the profile location for your installation is stored in the global variable $PSHOME. This isn't documented explicitly in the Windows installation instructions but is in a note in the Linux installation instructions.