From b9246177c04d8912c82fde77b60ddf397abbcd8c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 22:24:31 +0000 Subject: [PATCH 1/7] Initial plan From bbd7507b4ed6345749d6148b7fba29af9cede01d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 22:27:38 +0000 Subject: [PATCH 2/7] Add OSC 133;D support for command exit code tracking Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- README.md | 2 +- vendor/profile.ps1 | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c45e254..661ba39 100644 --- a/README.md +++ b/README.md @@ -354,7 +354,7 @@ 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](https://learn.microsoft.com/en-us/windows/terminal/tutorials/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. +⚠ *Note:* Cmder also includes built-in support for [Windows Terminal shell integration](https://learn.microsoft.com/en-us/windows/terminal/tutorials/shell-integration) via OSC 133 sequences (A, B, C, D) for PowerShell sessions. This enables features like command navigation (jump between commands), command selection, visual command separators, command exit code tracking, 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). diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index c77e81a..42728e2 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -221,6 +221,14 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS $lastSUCCESS = $? $realLastExitCode = $LastExitCode + # Emit OSC 133;D sequence for Windows Terminal shell integration + # This marks the end of command execution with the exit code + # Must be emitted before OSC 133;A (start of next prompt) + # Only active in Windows Terminal ($env:WT_SESSION) + if ($env:WT_SESSION) { + Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;D;$realLastExitCode$([char]7)" + } + # Emit OSC 9;9 sequence for Windows Terminal directory tracking # This enables "Duplicate Tab" and "Split Pane" to preserve the working directory # Only active in Windows Terminal ($env:WT_SESSION) or ConEmu ($env:ConEmuPID) From 4d259ba84c10727bcb8c769c1cfd849865e12e5f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 22:41:26 +0000 Subject: [PATCH 3/7] Consolidate terminal conditionals and add shell integration for bash and cmd.exe Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/git-prompt.sh | 33 +++++++++++++++++++++++++++++++++ vendor/init.bat | 7 ++++++- vendor/profile.ps1 | 42 ++++++++++++++++++------------------------ 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/vendor/git-prompt.sh b/vendor/git-prompt.sh index a37400b..27da0de 100644 --- a/vendor/git-prompt.sh +++ b/vendor/git-prompt.sh @@ -48,6 +48,34 @@ then fi else # Source: github.com/git-for-windows/build-extra/blob/main/git-extra/git-prompt.sh + + # Setup OSC 133 shell integration for Windows Terminal + if [ -n "$WT_SESSION" ]; then + __cmder_prompt_command() { + local exit_code=$? + # OSC 133;D - Mark end of command execution with exit code + printf '\e]133;D;%s\a' "$exit_code" + # OSC 133;A - Mark start of prompt + printf '\e]133;A\a' + return $exit_code + } + + # OSC 133;C - Mark start of command output (emitted right before command execution) + __cmder_preexec() { + printf '\e]133;C\a' + } + + # Append to PROMPT_COMMAND to emit sequences before each prompt + if [ -z "$PROMPT_COMMAND" ]; then + PROMPT_COMMAND="__cmder_prompt_command" + else + PROMPT_COMMAND="__cmder_prompt_command;$PROMPT_COMMAND" + fi + + # Use DEBUG trap to emit OSC 133;C before command execution + trap '__cmder_preexec' DEBUG + fi + PS1='\[\033]0;${TITLEPREFIX:+$TITLEPREFIX:}${PWD//[^[:ascii:]]/?}\007\]' # set window title to TITLEPREFIX (if set) and current working directory # PS1="$PS1"'\n' # new line (disabled) PS1="$PS1"'\[\033[32m\]' # change to green and bold @@ -80,6 +108,11 @@ else PS1="$PS1"'\[\033[30;1m\]' # change color to grey in bold PS1="$PS1"'λ ' # prompt: Cmder uses λ PS1="$PS1"'\[\033[0m\]' # reset color + + # OSC 133;B - Mark start of command input (Windows Terminal only) + if [ -n "$WT_SESSION" ]; then + PS1="$PS1"'\[\e]133;B\a\]' + fi fi MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc diff --git a/vendor/init.bat b/vendor/init.bat index 3d82855..70e05d5 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -221,7 +221,12 @@ goto :SKIP_CLINK chcp 65001>nul :: Revert back to plain cmd.exe prompt without clink - prompt $E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m + :: With Windows Terminal shell integration support (OSC 133 sequences) + if defined WT_SESSION ( + prompt $e]133;D$e\$e]133;A$e\$e]9;9;$P$e\$E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m$e]133;B$e\ + ) else ( + prompt $E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m + ) chcp %cp%>nul diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 42728e2..1339077 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -221,28 +221,23 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS $lastSUCCESS = $? $realLastExitCode = $LastExitCode - # Emit OSC 133;D sequence for Windows Terminal shell integration - # This marks the end of command execution with the exit code - # Must be emitted before OSC 133;A (start of next prompt) - # Only active in Windows Terminal ($env:WT_SESSION) - if ($env:WT_SESSION) { - Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;D;$realLastExitCode$([char]7)" - } - - # Emit OSC 9;9 sequence for Windows Terminal directory tracking - # This enables "Duplicate Tab" and "Split Pane" to preserve the working directory - # Only active in Windows Terminal ($env:WT_SESSION) or ConEmu ($env:ConEmuPID) - $loc = $executionContext.SessionState.Path.CurrentLocation - if (($env:WT_SESSION -or $env:ConEmuPID) -and $loc.Provider.Name -eq "FileSystem") { - Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]9;9;`"$($loc.ProviderPath)`"$([char]0x1B)\" - } - - # 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]0x1B)]133;A$([char]7)" + # Emit terminal-specific escape sequences for Windows Terminal and ConEmu + if ($env:WT_SESSION -or $env:ConEmuPID) { + # OSC 133;D - Mark end of command execution with exit code (Windows Terminal only) + if ($env:WT_SESSION) { + Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;D;$realLastExitCode$([char]7)" + } + + # OSC 9;9 - Enable directory tracking for "Duplicate Tab" and "Split Pane" + $loc = $executionContext.SessionState.Path.CurrentLocation + if ($loc.Provider.Name -eq "FileSystem") { + Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]9;9;`"$($loc.ProviderPath)`"$([char]0x1B)\" + } + + # OSC 133;A - Mark start of prompt (Windows Terminal only) + if ($env:WT_SESSION) { + Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;A$([char]7)" + } } $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 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) + # OSC 133;B - Mark start of command input (Windows Terminal only) if ($env:WT_SESSION) { Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;B$([char]7)" } From 5dfa14ccce600fbe3e967cca150d6cd398c5a6c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 8 Nov 2025 22:55:15 +0000 Subject: [PATCH 4/7] Avoid duplicating cmd.exe prompt definition Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com> --- vendor/init.bat | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/vendor/init.bat b/vendor/init.bat index 70e05d5..2eabb6e 100644 --- a/vendor/init.bat +++ b/vendor/init.bat @@ -221,12 +221,10 @@ goto :SKIP_CLINK chcp 65001>nul :: Revert back to plain cmd.exe prompt without clink - :: With Windows Terminal shell integration support (OSC 133 sequences) - if defined WT_SESSION ( - prompt $e]133;D$e\$e]133;A$e\$e]9;9;$P$e\$E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m$e]133;B$e\ - ) else ( - prompt $E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m - ) + prompt $E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m + + :: Add Windows Terminal shell integration support (OSC 133 sequences) + if defined WT_SESSION (prompt $e]133;D$e\$e]133;A$e\$e]9;9;$P$e\%PROMPT%$e]133;B$e\) chcp %cp%>nul From 2ce0146d6eac72e62878b64ec0974393a33e13d4 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sun, 9 Nov 2025 02:45:06 +0330 Subject: [PATCH 5/7] adjust comments --- vendor/git-prompt.sh | 29 ++++++++++++++++------------- vendor/profile.ps1 | 17 +++++++++-------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/vendor/git-prompt.sh b/vendor/git-prompt.sh index 27da0de..8149695 100644 --- a/vendor/git-prompt.sh +++ b/vendor/git-prompt.sh @@ -47,25 +47,21 @@ then . ~/.config/git/git-prompt.sh fi else - # Source: github.com/git-for-windows/build-extra/blob/main/git-extra/git-prompt.sh - + # Setup OSC 133 shell integration for Windows Terminal if [ -n "$WT_SESSION" ]; then __cmder_prompt_command() { local exit_code=$? - # OSC 133;D - Mark end of command execution with exit code + # Emit OSC 133;D to mark the end of command execution with exit code printf '\e]133;D;%s\a' "$exit_code" - # OSC 133;A - Mark start of prompt - printf '\e]133;A\a' return $exit_code } - - # OSC 133;C - Mark start of command output (emitted right before command execution) + __cmder_preexec() { - printf '\e]133;C\a' + printf '\e]133;C\a' # Emit OSC 133;C to mark the start of command execution } - - # Append to PROMPT_COMMAND to emit sequences before each prompt + + # Append to PROMPT_COMMAND to emit sequences just before each prompt if [ -z "$PROMPT_COMMAND" ]; then PROMPT_COMMAND="__cmder_prompt_command" else @@ -75,9 +71,16 @@ else # Use DEBUG trap to emit OSC 133;C before command execution trap '__cmder_preexec' DEBUG fi - + + # Source: github.com/git-for-windows/build-extra/blob/main/git-extra/git-prompt.sh PS1='\[\033]0;${TITLEPREFIX:+$TITLEPREFIX:}${PWD//[^[:ascii:]]/?}\007\]' # set window title to TITLEPREFIX (if set) and current working directory # PS1="$PS1"'\n' # new line (disabled) + + if [ -n "$WT_SESSION" ]; then + # Emit OSC 133;A to mark the start of prompt + PS1="$PS1"'\e]133;A\a' + fi + PS1="$PS1"'\[\033[32m\]' # change to green and bold PS1="$PS1"'\u@\h ' # user@host PS1="$PS1${MSYSTEM:+\[\033[35m\]$MSYSTEM }" # show MSYSTEM in purple (if set) @@ -108,9 +111,9 @@ else PS1="$PS1"'\[\033[30;1m\]' # change color to grey in bold PS1="$PS1"'λ ' # prompt: Cmder uses λ PS1="$PS1"'\[\033[0m\]' # reset color - - # OSC 133;B - Mark start of command input (Windows Terminal only) + if [ -n "$WT_SESSION" ]; then + # Emit OSC 133;B to mark the end of prompt PS1="$PS1"'\[\e]133;B\a\]' fi fi diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 1339077..8e20d0c 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -98,8 +98,7 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") { # Display an extra prompt line between the prompt and the command input 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) + # Invoked when Enter is pressed to submit a command if ($env:WT_SESSION) { Set-PSReadLineKeyHandler -Key Enter -ScriptBlock { # Get the current command line @@ -110,7 +109,7 @@ if (Get-Module PSReadline -ErrorAction "SilentlyContinue") { # Accept the line first [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() - # Emit OSC 133;C sequence to mark start of command output + # Emit OSC 133;C to mark start of command output # This is written directly to the console after the command is accepted [Console]::Write("$([char]0x1B)]133;C$([char]7)") } @@ -221,20 +220,22 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS $lastSUCCESS = $? $realLastExitCode = $LastExitCode - # Emit terminal-specific escape sequences for Windows Terminal and ConEmu + # Terminal-specific escape sequences for Windows Terminal and ConEmu if ($env:WT_SESSION -or $env:ConEmuPID) { - # OSC 133;D - Mark end of command execution with exit code (Windows Terminal only) + # Emit OSC 133;D to mark the end of command execution with exit code if ($env:WT_SESSION) { Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;D;$realLastExitCode$([char]7)" } - # OSC 9;9 - Enable directory tracking for "Duplicate Tab" and "Split Pane" + # Emit OSC 9;9 to mark the start of the prompt + # Enables directory tracking for "Duplicate Tab" and "Split Pane" $loc = $executionContext.SessionState.Path.CurrentLocation if ($loc.Provider.Name -eq "FileSystem") { Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]9;9;`"$($loc.ProviderPath)`"$([char]0x1B)\" } - # OSC 133;A - Mark start of prompt (Windows Terminal only) + # Emit OSC 133;A to mark the start of the prompt + # Enables features like command navigation, selection, and visual separators if ($env:WT_SESSION) { Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;A$([char]7)" } @@ -249,7 +250,7 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS CmderPrompt PostPrompt | Microsoft.PowerShell.Utility\Write-Host -NoNewline - # OSC 133;B - Mark start of command input (Windows Terminal only) + # Emit OSC 133;B to mark the start of command input (after prompt, before user types) if ($env:WT_SESSION) { Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;B$([char]7)" } From 7b248bc9a3668b3b7ac56993d32b09e00e18eee9 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sun, 9 Nov 2025 02:50:47 +0330 Subject: [PATCH 6/7] adjust comments --- vendor/git-prompt.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vendor/git-prompt.sh b/vendor/git-prompt.sh index 8149695..e64f906 100644 --- a/vendor/git-prompt.sh +++ b/vendor/git-prompt.sh @@ -58,7 +58,8 @@ else } __cmder_preexec() { - printf '\e]133;C\a' # Emit OSC 133;C to mark the start of command execution + # Emit OSC 133;C to mark the start of command execution + printf '\e]133;C\a' } # Append to PROMPT_COMMAND to emit sequences just before each prompt @@ -67,7 +68,7 @@ else else PROMPT_COMMAND="__cmder_prompt_command;$PROMPT_COMMAND" fi - + # Use DEBUG trap to emit OSC 133;C before command execution trap '__cmder_preexec' DEBUG fi From eabadf96dc66be16091d2fc33c147f239d5a940d Mon Sep 17 00:00:00 2001 From: David Refoua Date: Sun, 9 Nov 2025 02:57:19 +0330 Subject: [PATCH 7/7] fix incorrect comment --- vendor/profile.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vendor/profile.ps1 b/vendor/profile.ps1 index 8e20d0c..359c9d3 100644 --- a/vendor/profile.ps1 +++ b/vendor/profile.ps1 @@ -227,8 +227,8 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]133;D;$realLastExitCode$([char]7)" } - # Emit OSC 9;9 to mark the start of the prompt - # Enables directory tracking for "Duplicate Tab" and "Split Pane" + # Emit OSC 9;9 to enable directory tracking + # Enables "Duplicate Tab" and "Split Pane" to preserve the working directory $loc = $executionContext.SessionState.Path.CurrentLocation if ($loc.Provider.Name -eq "FileSystem") { Microsoft.PowerShell.Utility\Write-Host -NoNewline "$([char]0x1B)]9;9;`"$($loc.ProviderPath)`"$([char]0x1B)\"