-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiterm_controller.sh
More file actions
executable file
·156 lines (139 loc) · 3.96 KB
/
iterm_controller.sh
File metadata and controls
executable file
·156 lines (139 loc) · 3.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/bash
# iTerm2 Controller Script
# Manages panes for Claude Code collaboration
SCRIPT_NAME="iterm_controller.sh"
show_help() {
echo "iTerm2 Controller for Claude Code Collaboration"
echo ""
echo "Usage: $SCRIPT_NAME <command> [options]"
echo ""
echo "Commands:"
echo " split-current - Split current window vertically"
echo " send <window> <pane> <cmd> - Send command to specific pane (1-indexed)"
echo " capture <window> <pane> [lines] - Capture last N lines (default 20)"
echo " list - List all windows and panes"
echo " focus <window> <pane> - Focus specific pane"
echo ""
echo "Examples:"
echo " $SCRIPT_NAME split-current"
echo " $SCRIPT_NAME send 1 2 'cd /Users/j/Code/athena/ash_chat/tui_chat'"
echo " $SCRIPT_NAME send 1 2 'mix run -e \"TuiChat.CLI.main([])\"'"
echo " $SCRIPT_NAME capture 1 2 10"
echo " $SCRIPT_NAME send 1 2 $'\\003' # Send Ctrl+C"
}
split_current_window() {
local window_name="${1:-dev-window}"
osascript <<EOF
tell application "iTerm2"
tell current window
tell current session
-- Split vertically (right pane)
set newSession to (split vertically with default profile)
end tell
-- Return window ID for reference
return id
end tell
end tell
EOF
}
send_command() {
local window_index="$1"
local pane_index="$2"
local command="$3"
if [[ -z "$window_index" || -z "$pane_index" || -z "$command" ]]; then
echo "Error: send requires window_index, pane_index, and command"
exit 1
fi
osascript <<EOF
tell application "iTerm2"
tell window $window_index
tell session $pane_index
write text "$command"
end tell
end tell
end tell
EOF
}
capture_output() {
local window_index="$1"
local pane_index="$2"
local lines="${3:-20}"
if [[ -z "$window_index" || -z "$pane_index" ]]; then
echo "Error: capture requires window_index and pane_index"
exit 1
fi
osascript <<EOF
tell application "iTerm2"
tell window $window_index
tell session $pane_index
get text of (lines -$lines thru -1)
end tell
end tell
end tell
EOF
}
list_sessions() {
osascript <<EOF
tell application "iTerm2"
set output to ""
repeat with w from 1 to count of windows
set currentWindow to window w
set output to output & "Window " & w & ": " & (name of currentWindow) & "\\n"
repeat with s from 1 to count of sessions of currentWindow
set currentSession to session s of currentWindow
set output to output & " Session " & s & ": " & (name of currentSession) & "\\n"
end repeat
end repeat
return output
end tell
EOF
}
focus_pane() {
local window_index="$1"
local pane_index="$2"
if [[ -z "$window_index" || -z "$pane_index" ]]; then
echo "Error: focus requires window_index and pane_index"
exit 1
fi
osascript <<EOF
tell application "iTerm2"
tell window $window_index
tell session $pane_index
select
end tell
end tell
end tell
EOF
}
# Main command dispatch
case "$1" in
"split-current")
echo "Splitting current window..."
window_id=$(split_current_window "$2")
echo "Created window: $window_id"
echo "Pane 0: Claude Code (left)"
echo "Pane 1: Available for commands (right)"
;;
"send")
send_command "$2" "$3" "$4"
echo "Command sent to window '$2', pane $3"
;;
"capture")
capture_output "$2" "$3" "$4"
;;
"list")
list_sessions
;;
"focus")
focus_pane "$2" "$3"
echo "Focused window '$2', pane $3"
;;
"help"|"-h"|"--help"|"")
show_help
;;
*)
echo "Unknown command: $1"
echo "Use '$SCRIPT_NAME help' for usage information"
exit 1
;;
esac