-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-template
More file actions
executable file
·341 lines (305 loc) · 11.4 KB
/
start-template
File metadata and controls
executable file
·341 lines (305 loc) · 11.4 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/bash
# ═══════════════════════════════════════════════════════════════
# DEV RUNNER - Quick Command TUI (shared via plaintext-scripts)
# Simple menu for common dev workflow actions.
#
# Reads configuration from build-conf.txt in the project root:
# WEBAPP_MODULE, TUI_TITLE, AUTOLOGIN_URL (optional)
#
# Copy this file to your project root as ./start
# ═══════════════════════════════════════════════════════════════
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$HOME/code/plaintext-scripts/tui-common.sh"
# ── Load build-conf.txt ──────────────────────────────────────
if [[ -f "$SCRIPT_DIR/build-conf.txt" ]]; then
while IFS='=' read -r key value; do
[[ "$key" =~ ^#.*$ ]] && continue
[[ -z "$key" ]] && continue
value="${value%%#*}"
value="${value%"${value##*[![:space:]]}"}"
export "$key"="$value"
done < "$SCRIPT_DIR/build-conf.txt"
fi
: "${WEBAPP_MODULE:?WEBAPP_MODULE must be set in build-conf.txt}"
: "${TUI_TITLE:=DEV RUNNER}"
source "$HOME/code/plaintext-scripts/tui-start-logic.sh"
# ── Non-interactive mode (CLI args) ─────────────────────────
if [[ -n "$1" ]]; then
case "$1" in
start|s) do_start; exit $? ;;
kill|k) do_kill; exit 0 ;;
install|i) do_clean_install; exit $? ;;
logs|l) do_logs; exit 0 ;;
modules|m) exec "$SCRIPT_DIR/modules" ;;
build|b) exec "$SCRIPT_DIR/build.sh" ;;
start-pg|pg) exec "$HOME/code/plaintext-scripts/start-postgres.sh" ;;
stop-pg) exec "$HOME/code/plaintext-scripts/stop-postgres.sh" ;;
voice|v) exec "$HOME/code/plaintext-scripts/voice" ;;
help|-h|--help)
echo -e "${FG_BLUE}${BOLD}${TUI_TITLE}${RESET}"
echo ""
echo -e " ${FG_CYAN}./start${RESET} Interactive TUI"
echo -e " ${FG_CYAN}./start start${RESET} Build + start"
echo -e " ${FG_CYAN}./start kill${RESET} Kill all Java processes"
echo -e " ${FG_CYAN}./start install${RESET} mvn clean install"
echo -e " ${FG_CYAN}./start logs${RESET} Open logs in new Terminal"
echo -e " ${FG_CYAN}./start modules${RESET} Open module manager"
echo -e " ${FG_CYAN}./start build${RESET} Run build.sh"
echo -e " ${FG_CYAN}./start start-pg${RESET} Start PostgreSQL"
echo -e " ${FG_CYAN}./start stop-pg${RESET} Stop PostgreSQL"
echo -e " ${FG_CYAN}./start voice${RESET} Voice-to-Claude"
exit 0
;;
*)
echo -e "${FG_RED}Unknown command: $1${RESET}"
echo "Use: ./start help"
exit 1
;;
esac
fi
# ── TUI ──────────────────────────────────────────────────────
# Menu items
MENU_LABELS=()
MENU_LABELS+=("Start (build + run)")
MENU_LABELS+=("Kill (stop app)")
MENU_LABELS+=("Clean Install (mvn)")
MENU_LABELS+=("Logs (tail in new terminal)")
MENU_LABELS+=("Modules (toggle modules)")
MENU_LABELS+=("Build (build.sh)")
MENU_LABELS+=("Start Postgres")
MENU_LABELS+=("Stop Postgres")
MENU_LABELS+=("Voice-to-Claude")
MENU_TOTAL=${#MENU_LABELS[@]}
MENU_MAX_IDX=$((MENU_TOTAL - 1))
CURSOR=0
STATUS_MSG=""
STATUS_COLOR=""
trap tui_cleanup EXIT
tui_init
# ── Drawing ──────────────────────────────────────────────────
draw() {
tput clear
local app_status
app_status=$(get_status_line)
local total_lines=$((1 + 3 + 1 + 1 + 1 + MENU_TOTAL + 1 + 1 + 1 + 1))
[[ -n "$STATUS_MSG" ]] && total_lines=$((total_lines + 1))
tui_center $total_lines
# ── Top border ──
tui_hline "┌" "─" "┐"
# ── Header band ──
tui_nr; tui_band_row
tui_nr; tui_band_title "$TUI_TITLE"
tui_nr; tui_band_row
# ── App status ──
local status_color="$FG_GREEN"
if [[ "$app_status" == "stopped" ]]; then
status_color="$FG_DIM"
fi
tui_nr; tui_row " App: ${app_status}" "${status_color}"
# ── Status message (action feedback) ──
if [[ -n "$STATUS_MSG" ]]; then
tui_nr; tui_row " ${STATUS_MSG}" "${STATUS_COLOR}"
fi
# ── Separator ──
tui_nr; tui_hline "├" "─" "┤"
# ── Blank line ──
tui_nr; tui_row "" ""
# ── Menu items ──
local i
for ((i=0; i<MENU_TOTAL; i++)); do
tui_nr
if [[ $CURSOR -eq $i ]]; then
tui_item_on "${MENU_LABELS[$i]}"
else
tui_item_off "${MENU_LABELS[$i]}"
fi
done
# ── Blank line ──
tui_nr; tui_row "" ""
# ── Footer ──
tui_nr; tui_hline "├" "─" "┤"
tui_nr; tui_row " Up/Down Navigate ENTER Run H Help Q Quit" "${FG_DIM}"
tui_nr; tui_hline "└" "─" "┘"
}
# ── Help Screen ──────────────────────────────────────────────
show_help() {
tput clear
tui_center 23
tui_hline "┌" "─" "┐"
tui_nr; tui_row "" ""
tui_nr; tui_row " ${TUI_TITLE} - HELP" "${FG_WHITE}${BOLD}"
tui_nr; tui_row "" ""
tui_nr; tui_hline "├" "─" "┤"
tui_nr; tui_row " Tastatur:" "${FG_CYAN}${BOLD}"
tui_nr; tui_row " Up Down Navigieren" "${FG_CYAN}"
tui_nr; tui_row " ENTER Auswahl ausfuehren" "${FG_CYAN}"
tui_nr; tui_row " Q Beenden" "${FG_CYAN}"
tui_nr; tui_row "" ""
tui_nr; tui_row " CLI:" "${FG_CYAN}${BOLD}"
tui_nr; tui_row " ./start start Bauen + Starten" "${FG_CYAN}"
tui_nr; tui_row " ./start kill Java beenden" "${FG_CYAN}"
tui_nr; tui_row " ./start install mvn clean install" "${FG_CYAN}"
tui_nr; tui_row " ./start logs Logs oeffnen" "${FG_CYAN}"
tui_nr; tui_row " ./start modules Module verwalten" "${FG_CYAN}"
tui_nr; tui_row " ./start build Build System" "${FG_CYAN}"
tui_nr; tui_row " ./start start-pg PostgreSQL starten" "${FG_CYAN}"
tui_nr; tui_row " ./start stop-pg PostgreSQL stoppen" "${FG_CYAN}"
tui_nr; tui_row " ./start voice Voice-to-Claude" "${FG_CYAN}"
tui_nr; tui_row "" ""
tui_nr; tui_hline "├" "─" "┤"
tui_nr; tui_row " Beliebige Taste zum Schliessen..." "${FG_DIM}"
tui_nr; tui_hline "└" "─" "┘"
IFS= read -rsn1
}
# ── Command Execution ────────────────────────────────────────
execute_command() {
local idx="$1"
case "$idx" in
0) # Start - open in new terminal
osascript << EOF 2>/dev/null &
tell application "Terminal"
set newTab to do script "cd \"${SCRIPT_DIR}\" && ./start start; exit"
set targetWindow to window 1
repeat
delay 5
try
if not busy of newTab then
close targetWindow saving no
exit repeat
end if
end try
end repeat
end tell
EOF
STATUS_MSG="Build+Start opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
1) # Kill
do_kill
STATUS_MSG="Application stopped"
STATUS_COLOR="$FG_RED"
;;
2) # Clean Install - open in new terminal
osascript << EOF 2>/dev/null &
tell application "Terminal"
set newTab to do script "cd \"${SCRIPT_DIR}\" && ./start install; exit"
set targetWindow to window 1
repeat
delay 5
try
if not busy of newTab then
close targetWindow saving no
exit repeat
end if
end try
end repeat
end tell
EOF
STATUS_MSG="Clean Install opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
3) # Logs
do_logs
STATUS_MSG="Logs opened"
STATUS_COLOR="$FG_GREEN"
;;
4) # Modules - open in new terminal
osascript << EOF 2>/dev/null &
tell application "Terminal"
set newTab to do script "cd \"${SCRIPT_DIR}\" && ./modules; exit"
set targetWindow to window 1
repeat
delay 2
try
if not busy of newTab then
close targetWindow saving no
exit repeat
end if
end try
end repeat
end tell
EOF
STATUS_MSG="Modules opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
5) # Build - open in new terminal
osascript -e "tell application \"Terminal\" to do script \"cd \\\"${SCRIPT_DIR}\\\" && ./build.sh\"" 2>/dev/null || true
STATUS_MSG="Build opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
6) # Start Postgres
osascript << EOF 2>/dev/null &
tell application "Terminal"
set newTab to do script "cd \"${SCRIPT_DIR}\" && ~/code/plaintext-scripts/start-postgres.sh; exit"
set targetWindow to window 1
repeat
delay 2
try
if not busy of newTab then
close targetWindow saving no
exit repeat
end if
end try
end repeat
end tell
EOF
STATUS_MSG="Start Postgres opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
7) # Stop Postgres
osascript << EOF 2>/dev/null &
tell application "Terminal"
set newTab to do script "cd \"${SCRIPT_DIR}\" && ~/code/plaintext-scripts/stop-postgres.sh; exit"
set targetWindow to window 1
repeat
delay 2
try
if not busy of newTab then
close targetWindow saving no
exit repeat
end if
end try
end repeat
end tell
EOF
STATUS_MSG="Stop Postgres opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
8) # Voice-to-Claude
osascript -e "tell application \"Terminal\" to do script \"cd \\\"${SCRIPT_DIR}\\\" && ~/code/plaintext-scripts/voice\"" 2>/dev/null || true
STATUS_MSG="Voice-to-Claude opened in new Terminal"
STATUS_COLOR="$FG_GREEN"
;;
esac
}
# ── Main loop ────────────────────────────────────────────────
draw
while true; do
IFS= read -rsn1 key
case "$key" in
$'\x1b')
read -rsn2 -t 1 seq || seq=""
case "$seq" in
'[A') # Up
[[ $CURSOR -gt 0 ]] && CURSOR=$((CURSOR - 1))
;;
'[B') # Down
[[ $CURSOR -lt $MENU_MAX_IDX ]] && CURSOR=$((CURSOR + 1))
;;
esac
;;
'') # Enter
execute_command "$CURSOR"
;;
'h'|'H'|'?')
show_help
;;
'q'|'Q')
tui_cleanup
echo ""
exit 0
;;
esac
draw
done