Powershell Core OSC9;9 string leaves residue in prompt after using grep from git-for-windows with pipe #18008

Closed
opened 2026-01-31 06:01:02 +00:00 by claunia · 6 comments
Owner

Originally created by @3N4N on GitHub (Jul 22, 2022).

This is a port of an issue previously filed here: https://github.com/MicrosoftDocs/terminal/issues/425.

Output of the bug

PS C:\Users\ACER> dir | grep 'pattern'           # no match
PS C:\Users\ACER> ←]9;9;"C:\Users\ACER"
PS C:\Users\ACER>
PS C:\Users\ACER> dir | grep 'Documents'     # matches
d-r--           10/9/2021 11:04 PM                Documents
PS C:\Users\ACER> ←]9;9;"C:\Users\ACER"
PS C:\Users\ACER>
PS C:\Users\ACER> grep -HnrIi 'damn' .\Documents\PowerShell\        # to show that without piping the bug doesn't appear
.\Documents\PowerShell\/Scripts/scratch.ps1:1:function Damn([string]$sym)
PS C:\Users\ACER>
PS C:\Users\ACER> dir | win32yank.exe -i  # to show that the problem is not with piping
PS C:\Users\ACER>

Reproduction steps

  1. Put the following in the $PROFILE.
    function prompt
    {
    $loc = Get-Location
    
    # Emulate standard PS prompt with location followed by ">"
    $out = "PS $loc> "
    
    # Add current working directory (FileSystem)
    if ($loc.Provider.Name -eq "FileSystem") {
        $out += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)"
    }
    
    return $out
    }
    
  2. Open a new PWSH tab in windows terminal.
  3. Make sure git is in the $env:path and invoke:
    dir | grep -i "pattern"
    

Versions of tools used

  • Windows Terminal: 1.15.2003.0 (why does wt -v not print in the console? I cannot even copy from the popup window.)
  • PowerShell Core: PowerShell 7.1.4
  • GIt for Windows: git version 2.33.0.windows.2

Discussions elsewhere

I mentioned in another issue -- may or may not be related -- that Windows Terminal crashes randomly if I use OSC9;9 string in the prompt. But I've been using the preview build for a week and it hasn't crashed yet. Update: I have had no crashes since then.

Originally created by @3N4N on GitHub (Jul 22, 2022). This is a port of an issue previously filed here: https://github.com/MicrosoftDocs/terminal/issues/425. ## Output of the bug ```ps1 PS C:\Users\ACER> dir | grep 'pattern' # no match PS C:\Users\ACER> ←]9;9;"C:\Users\ACER" PS C:\Users\ACER> PS C:\Users\ACER> dir | grep 'Documents' # matches d-r-- 10/9/2021 11:04 PM Documents PS C:\Users\ACER> ←]9;9;"C:\Users\ACER" PS C:\Users\ACER> PS C:\Users\ACER> grep -HnrIi 'damn' .\Documents\PowerShell\ # to show that without piping the bug doesn't appear .\Documents\PowerShell\/Scripts/scratch.ps1:1:function Damn([string]$sym) PS C:\Users\ACER> PS C:\Users\ACER> dir | win32yank.exe -i # to show that the problem is not with piping PS C:\Users\ACER> ``` ## Reproduction steps 1. Put the following in the `$PROFILE`. ```ps1 function prompt { $loc = Get-Location # Emulate standard PS prompt with location followed by ">" $out = "PS $loc> " # Add current working directory (FileSystem) if ($loc.Provider.Name -eq "FileSystem") { $out += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)" } return $out } ``` 2. Open a new PWSH tab in windows terminal. 3. Make sure `git` is in the `$env:path` and invoke: ```ps1 dir | grep -i "pattern" ``` ## Versions of tools used - Windows Terminal: 1.15.2003.0 (why does `wt -v` not print in the console? I cannot even copy from the popup window.) - PowerShell Core: PowerShell 7.1.4 - GIt for Windows: git version 2.33.0.windows.2 ## Discussions elsewhere I mentioned in [another issue](https://github.com/MicrosoftDocs/terminal/issues/285#issuecomment-937792680) -- may or may not be related -- that Windows Terminal crashes randomly if I use OSC9;9 string in the prompt. But I've been using the preview build for a week and it hasn't crashed yet. **Update**: I have had no crashes since then.
claunia added the Resolution-Duplicate label 2026-01-31 06:01:02 +00:00
Author
Owner

@DHowett commented on GitHub (Jul 22, 2022):

why does wt -v not print in the console?

It is too sad to countenance. Funny enough, if you press Ctrl+C in any standard Windows message box, it DOES unexpectedly give you a hard copy of it:

---------------------------
Help
---------------------------
Windows Terminal Preview
1.16.2004.0
---------------------------
OK   
---------------------------

I'm guessing this is related to msys restoring the console mode and turning off VT input . . . let me go digging, because I wrote this up before.

@DHowett commented on GitHub (Jul 22, 2022): > why does `wt -v` not print in the console? It is too sad to countenance. Funny enough, if you press <kbd>Ctrl+C</kbd> in any standard Windows message box, it DOES unexpectedly give you a hard copy of it: ``` --------------------------- Help --------------------------- Windows Terminal Preview 1.16.2004.0 --------------------------- OK --------------------------- ``` I'm guessing this is related to msys restoring the console mode and turning off VT input . . . let me go digging, because I wrote this up before.
Author
Owner

@3N4N commented on GitHub (Jul 22, 2022):

let me go digging, because I wrote this up before.

This is way too fast a response. I feel guilty now. Take your time.

Funny enough, if you press Ctrl+C in any standard Windows message box, it DOES unexpectedly give you a hard copy of it

Live and learn.

@3N4N commented on GitHub (Jul 22, 2022): > let me go digging, because I wrote this up before. This is *way* too fast a response. I feel guilty now. Take your time. > Funny enough, if you press Ctrl+C in any standard Windows message box, it DOES unexpectedly give you a hard copy of it Live and learn.
Author
Owner

@DHowett commented on GitHub (Jul 22, 2022):

I feel guilty now.

Ha, don't! It's not a problem at all.

The symptoms here feel very similar to the ones dissected in https://github.com/microsoft/terminal/issues/4921#issuecomment-599135352, which we traced back to an issue in the MSYS2 runtime that Git uses. I'm not sure whether the state of this issue has changed between 2.33 (the version you have installed) and 2.37 (the current version).

@DHowett commented on GitHub (Jul 22, 2022): > I feel guilty now. Ha, don't! It's not a problem at all. The symptoms here feel very similar to the ones dissected in https://github.com/microsoft/terminal/issues/4921#issuecomment-599135352, which we traced back to an issue in the MSYS2 runtime that Git uses. I'm not sure whether the state of this issue has changed between 2.33 (the version you have installed) and 2.37 (the current version).
Author
Owner

@3N4N commented on GitHub (Jul 22, 2022):

I can reproduce issue 4921. Although, I need to press enter once, then ←]9;9;"C:\Users\ACER" appears. Also, after git gui, if I run a command that produces an exception (apparently powershell errors and exceptions are different), the output is like this.

C:\Users\ACER> git gui
C:\Users\ACER> wrong_cmd hello world
←[91mwrong_cmd: ←[91mThe term 'wrong_cmd' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.←[0m
C:\Users\ACER> ←]9;9;"C:\Users\ACER"

So, basically terminal loses the ability to recognize the escape/special characters as escape/special characters, right?

I'm not sure whether the state of this issue has changed between 2.33 (the version you have installed) and 2.37 (the current version).

This issue persists with Msys2's grep command, too. And I regularly update msys.

@3N4N commented on GitHub (Jul 22, 2022): I can reproduce issue 4921. Although, I need to press enter once, then `←]9;9;"C:\Users\ACER"` appears. Also, after `git gui`, if I run a command that produces an exception (apparently powershell errors and exceptions are different), the output is like this. ``` C:\Users\ACER> git gui C:\Users\ACER> wrong_cmd hello world ←[91mwrong_cmd: ←[91mThe term 'wrong_cmd' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.←[0m C:\Users\ACER> ←]9;9;"C:\Users\ACER" ``` So, basically terminal loses the ability to recognize the escape/special characters as escape/special characters, right? > I'm not sure whether the state of this issue has changed between 2.33 (the version you have installed) and 2.37 (the current version). This issue persists with Msys2's grep command, too. And I regularly update msys.
Author
Owner

@zadjii-msft commented on GitHub (Jul 25, 2022):

Yea, this looks like the same thing. I'm game to call this a dupe (and reopen if I'm wrong).

/dup #4921

@zadjii-msft commented on GitHub (Jul 25, 2022): Yea, this looks like the same thing. I'm game to call this a dupe (and reopen if I'm wrong). /dup #4921
Author
Owner

@ghost commented on GitHub (Jul 25, 2022):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Jul 25, 2022): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18008