Consolidate terminal conditionals and add shell integration for bash and cmd.exe

Co-authored-by: DRSDavidSoft <4673812+DRSDavidSoft@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-11-08 22:41:26 +00:00
parent bbd7507b4e
commit 4d259ba84c
3 changed files with 57 additions and 25 deletions

33
vendor/git-prompt.sh vendored
View File

@@ -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

7
vendor/init.bat vendored
View File

@@ -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

38
vendor/profile.ps1 vendored
View File

@@ -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 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)"
}
# 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)\"
}
# 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)\"
}
# 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)"
# 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)"
}