powershellescapingconsole2posh-git

Setting WindowTitle of PowerShell posh-git - escape hyphen?


I'm trying to set the WindowTitle of Powershell (hosted by Console) to match the output of my posh-git prompt. So if I had one modified file, my prompt would look something like;

[Repo master +0 ~1 -0]

I'd like to set the $Host.UI.RawUI.WindowTitle equal to the same sort of thing, but the '-0' part of the string seems to be some sort of escape sequence. If I do something like this:

$repoName = Split-Path -Leaf (Split-Path $GitStatus.GitDir)
$title = "[$repoName $($GitStatus.Branch)"

if($GitPromptSettings.EnableFileStatus -and $GitStatus.HasWorking) {
    $title += " +$($GitStatus.Working.Added.Count)"
    $title += " ~$($GitStatus.Working.Modified.Count)"
    $title += " -$($GitStatus.Working.Deleted.Count)"

    if ($GitStatus.Working.Unmerged) {
        $title += " !$($GitStatus.Working.Unmerged.Count)"
    }
}

$title += "]"
$Host.UI.RawUI.WindowTitle = $title

All I get is '-0]'. Any ideas on to provide an escape character so that this will function properly?

If I change the '-' character to ~, then I get entire title as:

[Repo master +0 ~1 ~0]

Thanks in advance.


Solution

  • This is a bug with Console2. See #421 Tab titles containing dash are truncated for a similar bug report.

    Also, Dash causes corruption in window title talks about the issue, but it seems they haven't fixed it yet.

    With a different PowerShell host the code works fine with hyphens in the title.