Skip to content

Commit 1f70cfa

Browse files
authored
Merge pull request #3026 from cmderdev/copilot/fix-3025
Add OSC 9;9 support for PowerShell prompt to enable Windows Terminal directory tracking
2 parents 89ec06b + 545331a commit 1f70cfa

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ Cmder by default comes with a vendored ConEmu installation as the underlying ter
352352

353353
However, Cmder can in fact run in a variety of other terminal emulators, and even integrated IDEs. Assuming you have the latest version of Cmder, follow the following instructions to get Cmder working with your own terminal emulator.
354354

355+
*Note:* Cmder includes built-in support for Windows Terminal directory tracking via OSC 9;9 sequences. This enables "Duplicate Tab" and "Split Pane" features to preserve the current working directory for both `cmd.exe` and PowerShell sessions.
356+
355357
For instructions on how to integrate Cmder with your IDE, please read our [Wiki section](https://github.com/cmderdev/cmder/wiki#cmder-integration).
356358

357359
## Upgrading

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)