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

Open
opened 2026-01-31 06:00:59 +00:00 by claunia · 0 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:00:59 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#18005