Add OSC 9;9 support for PowerShell prompt to enable Windows Terminal directory tracking

Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-09-16 10:52:13 +00:00
parent 218400a4b8
commit 08ce81609a

9
vendor/profile.ps1 vendored
View File

@ -196,6 +196,15 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
[ScriptBlock]$Prompt = { [ScriptBlock]$Prompt = {
$lastSUCCESS = $? $lastSUCCESS = $?
$realLastExitCode = $LastExitCode $realLastExitCode = $LastExitCode
# Emit OSC 9;9 sequence for Windows Terminal directory tracking
# This enables "Duplicate Tab" and "Split Pane" to preserve the working directory
# Only active in Windows Terminal ($env:WT_SESSION) or ConEmu ($env:ConEmuPID)
$loc = $executionContext.SessionState.Path.CurrentLocation
if (($env:WT_SESSION -or $env:ConEmuPID) -and $loc.Provider.Name -eq "FileSystem") {
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]27)]9;9;`"$($loc.ProviderPath)`"$([char]27)\"
}
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf $host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x200B)`r$([char]0x1B)[K" Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x200B)`r$([char]0x1B)[K"
if ($lastSUCCESS -or ($LastExitCode -ne 0)) { if ($lastSUCCESS -or ($LastExitCode -ne 0)) {