mirror of
https://github.com/cmderdev/cmder.git
synced 2025-11-09 05:39:03 +08:00
Add OSC 133 shell integration sequences for Windows Terminal PowerShell support
This commit is contained in:
@@ -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 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).
|
For instructions on how to integrate Cmder with your IDE, please read our [Wiki section](https://github.com/cmderdev/cmder/wiki#cmder-integration).
|
||||||
|
|
||||||
## Upgrading
|
## Upgrading
|
||||||
|
|||||||
33
vendor/profile.ps1
vendored
33
vendor/profile.ps1
vendored
@@ -91,6 +91,24 @@ if (Get-Command -Name "vim" -ErrorAction SilentlyContinue) {
|
|||||||
|
|
||||||
if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
|
if (Get-Module PSReadline -ErrorAction "SilentlyContinue") {
|
||||||
Set-PSReadlineOption -ExtraPromptLineCount 1
|
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.
|
# Pre-assign default prompt hooks so the first run of cmder gets a working prompt.
|
||||||
@@ -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)\"
|
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
|
$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)) {
|
||||||
@@ -213,6 +239,13 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
|
|||||||
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
PrePrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
||||||
CmderPrompt
|
CmderPrompt
|
||||||
PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline
|
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
|
$global:LastExitCode = $realLastExitCode
|
||||||
return " "
|
return " "
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user