Skip to content

Commit f5474f7

Browse files
committed
fix(steps1-5): anchor MCP grep patterns, fix BSD grep compat in step-5 Motion detection, missing local vars
1 parent fdaf11a commit f5474f7

1 file changed

Lines changed: 22 additions & 14 deletions

File tree

step-1/step-1-install.sh

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ detect_os() {
9696
fi
9797

9898
# Ensure every target file exists before we try to read/write it.
99+
local f
99100
for f in "${SHELL_RCS[@]}" "${SHELL_PROFILES[@]}"; do
100101
[ -e "$f" ] || touch "$f"
101102
done
@@ -146,8 +147,8 @@ install_build_tools() {
146147
echo -e " ${YELLOW}Click 'Install' and wait for it to finish.${NC}"
147148
echo -e " ${YELLOW}This can take a few minutes...${NC}"
148149
echo ""
149-
CLT_WAIT=0
150-
CLT_MAX=180
150+
local CLT_WAIT=0
151+
local CLT_MAX=180
151152
until xcode-select -p &>/dev/null; do
152153
sleep 5
153154
CLT_WAIT=$((CLT_WAIT + 1))
@@ -200,6 +201,7 @@ install_homebrew() {
200201

201202
# Pick the right brew prefix and eval it into THIS shell so subsequent
202203
# install_git / install_node steps see `brew`.
204+
local BREW_SHELLENV_LINE profile
203205
if [ -f /opt/homebrew/bin/brew ]; then
204206
eval "$(/opt/homebrew/bin/brew shellenv)"
205207
# shellcheck disable=SC2016
@@ -262,6 +264,7 @@ install_git() {
262264
# 7. Node.js via nvm
263265
# -----------------------------------------------------------------------------
264266
install_node() {
267+
local NODE_MAJOR
265268
if command -v node &>/dev/null; then
266269
NODE_MAJOR=$(node -v | sed 's/v//' | cut -d. -f1)
267270
if [ "$NODE_MAJOR" -ge 18 ]; then
@@ -307,7 +310,8 @@ install_claude_code() {
307310
local attempt=0
308311
local max_attempts=3
309312
local installed=0
310-
while [ $attempt -lt $max_attempts ]; do
313+
local backoff
314+
while [ "$attempt" -lt "$max_attempts" ]; do
311315
attempt=$((attempt + 1))
312316
if npm install -g @anthropic-ai/claude-code 2>/dev/null \
313317
|| sudo npm install -g @anthropic-ai/claude-code; then
@@ -320,14 +324,14 @@ install_claude_code() {
320324
break
321325
fi
322326
fi
323-
if [ $attempt -lt $max_attempts ]; then
324-
local backoff=$((attempt * 5))
327+
if [ "$attempt" -lt "$max_attempts" ]; then
328+
backoff=$((attempt * 5))
325329
warn "Claude Code install attempt $attempt/$max_attempts failed — retrying in ${backoff}s..."
326330
sleep "$backoff"
327331
fi
328332
done
329333

330-
if [ $installed -ne 1 ]; then
334+
if [ "$installed" -ne 1 ]; then
331335
fail "Claude Code installation failed after $max_attempts attempts. Check internet + npm registry access (https://registry.npmjs.org/), then re-run this installer."
332336
fi
333337

@@ -342,10 +346,11 @@ install_claude_code() {
342346
# fill gaps without duplicating. Also migrates the old `alias ctg=` line
343347
# (now replaced by ~/.local/bin/ctg which can do the token pre-check).
344348
local total_aliases_added=0
349+
local rc aliases_added_here
345350
for rc in "${SHELL_RCS[@]}"; do
346351
[ -e "$rc" ] || touch "$rc"
347352

348-
local aliases_added_here=0
353+
aliases_added_here=0
349354

350355
# Marker comment — only once per file
351356
if ! grep -q '# Claude Code shortcuts' "$rc" 2>/dev/null; then
@@ -354,14 +359,15 @@ install_claude_code() {
354359
fi
355360

356361
# Each alias — skip if already present in this rc
362+
local alias_line alias_name
357363
for alias_line in \
358364
"alias cskip='claude --dangerously-skip-permissions'" \
359365
"alias cc='claude'" \
360366
"alias ccr='claude --resume'" \
361367
"alias ccc='claude --continue'"; do
362-
ALIAS_NAME="${alias_line%%=*}"
363-
ALIAS_NAME="${ALIAS_NAME#alias }"
364-
if ! grep -q "alias ${ALIAS_NAME}=" "$rc" 2>/dev/null; then
368+
alias_name="${alias_line%%=*}"
369+
alias_name="${alias_name#alias }"
370+
if ! grep -q "alias ${alias_name}=" "$rc" 2>/dev/null; then
365371
echo "$alias_line" >> "$rc"
366372
aliases_added_here=$((aliases_added_here + 1))
367373
fi
@@ -432,8 +438,9 @@ run_self_test() {
432438
echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
433439
echo ""
434440

435-
TEST_PASS=0
436-
TEST_FAIL=0
441+
local TEST_PASS=0
442+
local TEST_FAIL=0
443+
local NODE_MAJOR
437444

438445
# Git
439446
if command -v git &>/dev/null; then
@@ -480,8 +487,9 @@ run_self_test() {
480487
# Shell aliases — success if each alias appears in AT LEAST ONE rc file.
481488
# On macOS we write to both zsh + bash, and finding it in either shell's
482489
# rc is enough (user only opens one shell at a time in practice).
483-
ALIAS_PASS=0
484-
ALIAS_TOTAL=4
490+
local ALIAS_PASS=0
491+
local ALIAS_TOTAL=4
492+
local alias_name found_in_any_rc rc
485493
for alias_name in cskip cc ccr ccc; do
486494
found_in_any_rc=0
487495
for rc in "${SHELL_RCS[@]}"; do

0 commit comments

Comments
 (0)