You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Powershell Core OSC9;9 string leaves residue in prompt after using grep from git-for-windows with pipe #425
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/202111: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
Put the following in the $PROFILE.
functionprompt
{
$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
}
Open a new PWSH tab in windows terminal.
Make sure git is in the $env:path and invoke:
dir | grep -i "pattern"
Versions of tools used
Windows Terminal: 1.10.2714.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.
Then tbbie pointed me to some other OSC9;9 string setups and when that didn't work he asked me to get the reproducible steps and create an issue. So here it is.
changed the title [-]Powershell Core OSC9;9 string leaves residue in prompt after using grep with pipe from git-for-windows[/-][+]Powershell Core OSC9;9 string leaves residue in prompt after using grep from git-for-windows with pipe[/+]on Oct 10, 2021
I may have found where the problem was. Get-Location actually returns an object. So, $loc wasn't really a string variable.
I have now changed it to (Get-Location).Path and the bug seems to be fixed.
- $loc = Get-Location+ $loc = (Get-Location).Path
Leaving the issue open for confirmation that the resolution makes sense.
EDIT: Never mind. Without $loc as Path object, the reason for using OSC9;9 -- new splits and tabs in current directory -- doesn't work. So, it's not a solution.
Anyway, I can't trivially replicate this locally, using that prompt script (or my own prompt via PowerLine).
I also confirmed that OSC9;9 was working, as my duplicate-tab command following cd C:\Projects started correctly in that directory.
That's Windows Terminal 1.10.2714.0, PowerShell 7.1.5, and Git for Windows 2.30.2.windows.1. So not precisely the same versions, but close enough that it's not an inherent WT failure.
One thing to try, see if this makes a difference:
function prompt
{
$out = ""
$loc = Get-Location
# Add current working directory (FileSystem)
if ($loc.Provider.Name -eq "FileSystem") {
$out += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)"
}
# Emulate standard PS prompt with location followed by ">"
$out += "PS $loc> "
return $out
}
i.e. make sure that the BEL character being used to terminate the OSC command isn't the last character in the prompt.
You could also try
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]27)\"
}
return $out
}
i.e. terminate the OSC command with the ST sequence (Esc+\) rather than BEL, in case something is incorrectly stripping the BEL there.
Activity
[-]Powershell Core OSC9;9 string leaves residue in prompt after using grep with pipe from git-for-windows[/-][+]Powershell Core OSC9;9 string leaves residue in prompt after using grep from git-for-windows with pipe[/+]3N4N commentedon Oct 10, 2021
I may have found where the problem was.
Get-Locationactually returns an object. So,$locwasn't really a string variable.I have now changed it to
(Get-Location).Pathand the bug seems to be fixed.Leaving the issue open for confirmation that the resolution makes sense.
EDIT: Never mind. Without
$locas Path object, the reason for using OSC9;9 -- new splits and tabs in current directory -- doesn't work. So, it's not a solution.Fix powershell prompt
TBBle commentedon Oct 18, 2021
In the posted script,
$locshouldn't be a string, because when it's used in theOCS 9;9string, the Path is extracted from it.Anyway, I can't trivially replicate this locally, using that prompt script (or my own prompt via PowerLine).
I also confirmed that
OSC9;9was working, as my duplicate-tab command followingcd C:\Projectsstarted correctly in that directory.That's Windows Terminal 1.10.2714.0, PowerShell 7.1.5, and Git for Windows 2.30.2.windows.1. So not precisely the same versions, but close enough that it's not an inherent WT failure.
One thing to try, see if this makes a difference:
i.e. make sure that the
BELcharacter being used to terminate the OSC command isn't the last character in the prompt.You could also try
i.e. terminate the OSC command with the ST sequence (
Esc+\) rather than BEL, in case something is incorrectly stripping the BEL there.mattwojo commentedon Dec 9, 2021
Closing -- this issue isn't related to a docs update, but should be reopened in the Terminal product repo: https://github.com/Microsoft/terminal
Thank you!