2

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.

Terry
  • 2,148
  • 2
  • 32
  • 53
  • 1
    Maybe a Console2 thing? Your code works fine for me. – Jason Shirk Mar 21 '14 at 01:20
  • You may try [ConsoleZ](https://github.com/cbucher/console) (Console fork) or [ConEmu](https://github.com/Maximus5/ConEmu). Both are actively maintained. – Maximus Mar 24 '14 at 07:25
  • Thanks @Maximus I'm trying ConsoleZ but it seems the caption is always in the form of [TabName] - ... where TabName is the actual tab name defined in ConsoleZ settings. It doesn't seem to show the text that I'm assigning. I've looked through ConsoleZ settings but not seeing anything obvious on how to expand that. Are you familiar with that? – Terry Mar 25 '14 at 12:01
  • No. I'm ConEmu's author... – Maximus Mar 25 '14 at 15:21

1 Answers1

2

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.

Jesse Good
  • 50,901
  • 14
  • 124
  • 166