Skip to content

Commit 08ce816

Browse files
CopilotDRSDavidSoft
andcommitted
Add OSC 9;9 support for PowerShell prompt to enable Windows Terminal directory tracking
Co-authored-by: DRSDavidSoft <[email protected]>
1 parent 218400a commit 08ce816

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

vendor/profile.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,15 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
196196
[ScriptBlock]$Prompt = {
197197
$lastSUCCESS = $?
198198
$realLastExitCode = $LastExitCode
199+
200+
# Emit OSC 9;9 sequence for Windows Terminal directory tracking
201+
# This enables "Duplicate Tab" and "Split Pane" to preserve the working directory
202+
# Only active in Windows Terminal ($env:WT_SESSION) or ConEmu ($env:ConEmuPID)
203+
$loc = $executionContext.SessionState.Path.CurrentLocation
204+
if (($env:WT_SESSION -or $env:ConEmuPID) -and $loc.Provider.Name -eq "FileSystem") {
205+
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]27)]9;9;`"$($loc.ProviderPath)`"$([char]27)\"
206+
}
207+
199208
$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
200209
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x200B)`r$([char]0x1B)[K"
201210
if ($lastSUCCESS -or ($LastExitCode -ne 0)) {

0 commit comments

Comments
 (0)