Skip to content

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

Closed

Description

@3N4N

This is a port of an issue previously filed here: MicrosoftDocs/terminal#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.

Activity

  1. ghost added
    Needs-Triage
    on Jul 22, 2022
  2. ghost added
    Needs-Tag-Fix
    on Jul 22, 2022
  3. DHowett commented on Jul 22, 2022

    @DHowett
    Member

    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.

  4. 3N4N commented on Jul 22, 2022

    @3N4N
    Author

    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.

  5. DHowett commented on Jul 22, 2022

    @DHowett
    Member

    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 #4921 (comment), 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).

  6. 3N4N commented on Jul 22, 2022

    @3N4N
    Author

    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.

  7. zadjii-msft commented on Jul 25, 2022

    @zadjii-msft
    Member

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

    /dup #4921

  8. ghost closed this as completedon Jul 25, 2022
  9. ghost removed
    Needs-Triage
    on Jul 25, 2022
  10. ghost added
    Resolution-Duplicate
    on Jul 25, 2022
  11. ghost removed
    Needs-Tag-Fix
    on Jul 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-Duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions