Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ However, Cmder can in fact run in a variety of other terminal emulators, and eve

⚠ *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.

⚠ *Note:* Cmder also includes built-in support for Windows Terminal shell integration via OSC 133 sequences (A, B, C) for PowerShell sessions. This enables features like command navigation (jump between commands), command selection, visual command separators, and improved command history management in Windows Terminal.

For instructions on how to integrate Cmder with your IDE, please read our [Wiki section](https://github.com/cmderdev/cmder/wiki#cmder-integration).

## Upgrading
Expand Down
33 changes: 33 additions & 0 deletions vendor/profile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ if (Get-Command -Name "vim" -ErrorAction SilentlyContinue) {

if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
Set-PSReadlineOption -ExtraPromptLineCount 1

# Add OSC 133;C support for Windows Terminal shell integration
# This marks the start of command output (emitted when Enter is pressed)
if ($env:WT_SESSION) {
Set-PSReadLineKeyHandler -Key Enter -ScriptBlock {
# Get the current command line
$line = $null
$cursor = $null
[Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor)

# Accept the line first
[Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()

# Emit OSC 133;C sequence to mark start of command output
# This is written directly to the console after the command is accepted
[Console]::Write("$([char]27)]133;C$([char]7)")
}
}
}

# Pre-assign default prompt hooks so the first run of cmder gets a working prompt.
Expand Down Expand Up @@ -205,6 +223,14 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]27)]9;9;`"$($loc.ProviderPath)`"$([char]27)\"
}

# Emit OSC 133;A sequence for Windows Terminal shell integration
# This marks the start of the prompt
# Enables features like command navigation, selection, and visual separators
# Only active in Windows Terminal ($env:WT_SESSION)
if ($env:WT_SESSION) {
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]27)]133;A$([char]7)"
}

$host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath -Leaf
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x200B)`r$([char]0x1B)[K"
if ($lastSUCCESS -or ($LastExitCode -ne 0)) {
Expand All @@ -213,6 +239,13 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
CmderPrompt
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline

# Emit OSC 133;B sequence for Windows Terminal shell integration
# This marks the start of command input (after prompt, before user types)
if ($env:WT_SESSION) {
Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]27)]133;B$([char]7)"
}

$global:LastExitCode = $realLastExitCode
return " "
}
Expand Down
Loading