This repository was archived by the owner on Apr 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshell-integration.bash
More file actions
71 lines (56 loc) · 1.96 KB
/
shell-integration.bash
File metadata and controls
71 lines (56 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# bashpilot shell integration
# Injects OSC 633 escape sequences for command lifecycle tracking.
# Sourced automatically by bashpilot when launching bash.
# Guard against double-sourcing
if [[ "$__BASH_MCP_INJECTED" == "1" ]]; then
return
fi
__BASH_MCP_INJECTED=1
# Save original PROMPT_COMMAND
__bash_mcp_original_prompt_command="$PROMPT_COMMAND"
# Track state to avoid duplicate emissions
__bash_mcp_in_command=0
# Emit OSC 633 sequence: \e]633;{code}[;{data}]\a
__bash_mcp_osc() {
printf '\e]633;%s\a' "$1"
}
# Called before each prompt is displayed (precmd equivalent)
__bash_mcp_precmd() {
local exit_code=$?
# If we were in a command, emit CommandFinished with exit code
if [[ "$__bash_mcp_in_command" == "1" ]]; then
__bash_mcp_osc "D;$exit_code"
__bash_mcp_in_command=0
fi
# Report current working directory
__bash_mcp_osc "P;Cwd=$(pwd)"
# Emit PromptStart
__bash_mcp_osc "A"
# Run original PROMPT_COMMAND
if [[ -n "$__bash_mcp_original_prompt_command" ]]; then
eval "$__bash_mcp_original_prompt_command"
fi
# Window title: append to PS1 so it runs AFTER MSYS's built-in title setting
if [[ -n "$__bashpilot_title" && "$__bashpilot_ps1_patched" != "1" ]]; then
PS1="$PS1"'\[\e]0;$__bashpilot_title\a\]'
__bashpilot_ps1_patched=1
fi
}
# Called after prompt, before command execution (via DEBUG trap)
__bash_mcp_preexec() {
# Skip if this is the PROMPT_COMMAND itself or a completion
if [[ "$BASH_COMMAND" == "__bash_mcp_precmd" ]] || \
[[ "$BASH_COMMAND" == "${PROMPT_COMMAND}"* ]]; then
return
fi
# Emit CommandStart (user pressed Enter, about to execute)
__bash_mcp_osc "C"
__bash_mcp_in_command=1
}
# Override MSYS/Git Bash title prefix
TITLEPREFIX="bashpilot"
# Install hooks
PROMPT_COMMAND="__bash_mcp_precmd"
trap '__bash_mcp_preexec' DEBUG
# Emit initial PromptStart + CommandStart marker so the first prompt is tracked
__bash_mcp_osc "B"