@@ -221,28 +221,23 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
221221 $lastSUCCESS = $?
222222 $realLastExitCode = $LastExitCode
223223
224- # Emit OSC 133;D sequence for Windows Terminal shell integration
225- # This marks the end of command execution with the exit code
226- # Must be emitted before OSC 133;A (start of next prompt)
227- # Only active in Windows Terminal ($env:WT_SESSION)
228- if ($env: WT_SESSION ) {
229- Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;D;$realLastExitCode $ ( [char ]7 ) "
230- }
231-
232- # Emit OSC 9;9 sequence for Windows Terminal directory tracking
233- # This enables "Duplicate Tab" and "Split Pane" to preserve the working directory
234- # Only active in Windows Terminal ($env:WT_SESSION) or ConEmu ($env:ConEmuPID)
235- $loc = $executionContext.SessionState.Path.CurrentLocation
236- if (($env: WT_SESSION -or $env: ConEmuPID ) -and $loc.Provider.Name -eq " FileSystem" ) {
237- Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]9;9;`" $ ( $loc.ProviderPath ) `" $ ( [char ]0x1B ) \"
238- }
239-
240- # Emit OSC 133;A sequence for Windows Terminal shell integration
241- # This marks the start of the prompt
242- # Enables features like command navigation, selection, and visual separators
243- # Only active in Windows Terminal ($env:WT_SESSION)
244- if ($env: WT_SESSION ) {
245- Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;A$ ( [char ]7 ) "
224+ # Emit terminal-specific escape sequences for Windows Terminal and ConEmu
225+ if ($env: WT_SESSION -or $env: ConEmuPID ) {
226+ # OSC 133;D - Mark end of command execution with exit code (Windows Terminal only)
227+ if ($env: WT_SESSION ) {
228+ Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;D;$realLastExitCode $ ( [char ]7 ) "
229+ }
230+
231+ # OSC 9;9 - Enable directory tracking for "Duplicate Tab" and "Split Pane"
232+ $loc = $executionContext.SessionState.Path.CurrentLocation
233+ if ($loc.Provider.Name -eq " FileSystem" ) {
234+ Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]9;9;`" $ ( $loc.ProviderPath ) `" $ ( [char ]0x1B ) \"
235+ }
236+
237+ # OSC 133;A - Mark start of prompt (Windows Terminal only)
238+ if ($env: WT_SESSION ) {
239+ Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;A$ ( [char ]7 ) "
240+ }
246241 }
247242
248243 $host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath - Leaf
@@ -254,8 +249,7 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
254249 CmderPrompt
255250 PostPrompt | Microsoft.PowerShell.Utility\Write-Host - NoNewline
256251
257- # Emit OSC 133;B sequence for Windows Terminal shell integration
258- # This marks the start of command input (after prompt, before user types)
252+ # OSC 133;B - Mark start of command input (Windows Terminal only)
259253 if ($env: WT_SESSION ) {
260254 Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;B$ ( [char ]7 ) "
261255 }
0 commit comments