Skip to content

Commit a545988

Browse files
committed
Update snake_spinner script to loop forever and capture PID for killing
1 parent 9b5596e commit a545988

1 file changed

Lines changed: 15 additions & 20 deletions

File tree

β€Žgit-commit-push-script.shβ€Ž

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,26 @@ BOLD='\033[1m'
2929
DIM='\033[2m'
3030
NC='\033[0m' # No Color
3131

32-
# Snake spinner β€” cycling snake glyphs while waiting.
33-
# Usage: snake_spinner PID [label]
34-
# PID = 0 β†’ run until killed (for server-start polling)
35-
# PID > 0 β†’ run until that process exits (for curl/LLM wait)
32+
# Snake spinner β€” loops forever until killed by the caller.
33+
# Usage: snake_spinner [label]
34+
# Run in background (&), capture PID, kill after the task completes.
3635
snake_spinner() {
37-
local pid=$1
38-
local label="${2:-Generating commit message}"
36+
local label="${1:-Generating commit message}"
3937
local frames=('⣾' '⣽' '⣻' 'Ⓙ' '⑿' '⣟' '⣯' '⣷')
4038
local col_arr=("$CYAN" "$BLUE" "$PURPLE" "$CYAN" "$BLUE" "$PURPLE" "$CYAN" "$BLUE")
4139
local nf=${#frames[@]}
4240
local i=0 step=0
43-
# 0.1s delay β†’ 10 steps = 1s; use pure bash integer math (no bc fork)
44-
local delay=0.1
4541

4642
while true; do
47-
# kill -0 is a bash builtin β€” no subprocess fork unlike ps -p
48-
if [ "$pid" -ne 0 ] && ! kill -0 "$pid" 2>/dev/null; then
49-
break
50-
fi
51-
5243
local secs=$(( step / 10 ))
5344
local tenths=$(( step % 10 ))
5445
local c="${col_arr[$i]}"
5546
printf "\r${c}${frames[$i]}${NC} ${WHITE}${label}${NC}${GRAY}...${NC} ${DIM}(${secs}.${tenths}s)${NC} "
56-
57-
sleep "$delay"
47+
# read -t is a bash builtin β€” zero subprocess forks vs sleep
48+
read -t 0.1 </dev/null 2>/dev/null || true
5849
i=$(( (i + 1) % nf ))
5950
step=$(( step + 1 ))
6051
done
61-
printf "\r${GREEN}βœ“${NC} ${WHITE}Done!${NC} \n"
6252
}
6353

6454
# Status messages
@@ -200,7 +190,7 @@ if [ -n "$SQUISH_BIN" ]; then
200190
$SQUISH_BIN serve ${SQUISH_MODEL:+--model $SQUISH_MODEL} --port "$_port" > /tmp/squish_serve.log 2>&1 &
201191
_serve_pid=$!
202192
# Run snake spinner in background while polling for server readiness
203-
snake_spinner 0 "Starting squish server" &
193+
snake_spinner "Starting squish server" &
204194
_snake_pid=$!
205195
_waited=0
206196
while [ $_waited -lt 90 ] && ! nc -z 127.0.0.1 "$_port" 2>/dev/null; do
@@ -286,18 +276,23 @@ PYEOF
286276
# Run squish with timeout and spinner
287277
print_step "Asking AI for commit message (Squish local LLM)..."
288278
_port="${SQUISH_PORT:-11435}"
289-
_llm_start=$(date +%s%3N)
279+
_llm_start=$SECONDS
290280
curl -s --max-time $TIMEOUT_SECONDS \
291281
-X POST "http://127.0.0.1:${_port}/v1/chat/completions" \
292282
-H "Content-Type: application/json" \
293283
-H "Authorization: Bearer ${SQUISH_API_KEY:-squish}" \
294284
-d "$PAYLOAD" 2>/tmp/squish_stderr.txt \
295285
> /tmp/squish_response.txt &
296286
LLM_PID=$!
297-
snake_spinner $LLM_PID "Generating commit message"
287+
# Spinner runs in background; wait reaps curl immediately in foreground
288+
snake_spinner "Generating commit message" &
289+
_SPINNER_PID=$!
298290
wait $LLM_PID
299291
exit_code=$?
300-
_llm_elapsed=$(echo "scale=2; ($(date +%s%3N) - $_llm_start) / 1000" | bc)
292+
kill $_SPINNER_PID 2>/dev/null
293+
wait $_SPINNER_PID 2>/dev/null
294+
printf "\r${GREEN}βœ“${NC} ${WHITE}Done!${NC} \n"
295+
_llm_elapsed=$(( SECONDS - _llm_start ))
301296
print_info "model response time: ${CYAN}${_llm_elapsed}s${NC}"
302297

303298
# ── Debug: result diagnostics ─────────────────────────────────────────

0 commit comments

Comments
Β (0)