fix: install.sh adds smoke test, settings verification, and error recovery
The script now: runs the binary with --test after install to verify it actually works, prints the statusLine JSON that was written to settings, handles corrupt/invalid settings.json by backing up and writing fresh, and emphasizes that Claude Code must be restarted to pick up the change. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
43
install.sh
43
install.sh
@@ -58,7 +58,8 @@ echo "[ok] Built: $(ls -lh "$BINARY" | awk '{print $5}')"
|
|||||||
mkdir -p "$INSTALL_DIR"
|
mkdir -p "$INSTALL_DIR"
|
||||||
cp "$BINARY" "$INSTALL_DIR/$BINARY_NAME"
|
cp "$BINARY" "$INSTALL_DIR/$BINARY_NAME"
|
||||||
chmod +x "$INSTALL_DIR/$BINARY_NAME"
|
chmod +x "$INSTALL_DIR/$BINARY_NAME"
|
||||||
echo "[ok] Installed to $INSTALL_DIR/$BINARY_NAME"
|
BINARY_PATH="$INSTALL_DIR/$BINARY_NAME"
|
||||||
|
echo "[ok] Installed to $BINARY_PATH"
|
||||||
|
|
||||||
# Verify it's on PATH
|
# Verify it's on PATH
|
||||||
if ! command -v "$BINARY_NAME" &>/dev/null; then
|
if ! command -v "$BINARY_NAME" &>/dev/null; then
|
||||||
@@ -66,33 +67,50 @@ if ! command -v "$BINARY_NAME" &>/dev/null; then
|
|||||||
echo " Add to your shell config: export PATH=\"$INSTALL_DIR:\$PATH\""
|
echo " Add to your shell config: export PATH=\"$INSTALL_DIR:\$PATH\""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Smoke test — verify the binary actually runs
|
||||||
|
if "$BINARY_PATH" --test --color=never >/dev/null 2>&1; then
|
||||||
|
echo "[ok] Binary smoke test passed"
|
||||||
|
else
|
||||||
|
echo "[warn] Binary smoke test failed (exit $?). It may still work inside Claude Code."
|
||||||
|
echo " Debug: $BINARY_PATH --test --dump-state=json"
|
||||||
|
fi
|
||||||
|
|
||||||
# ── Configure Claude Code settings.json ──────────────────────────────
|
# ── Configure Claude Code settings.json ──────────────────────────────
|
||||||
echo ""
|
echo ""
|
||||||
mkdir -p "$CLAUDE_DIR"
|
mkdir -p "$CLAUDE_DIR"
|
||||||
|
|
||||||
BINARY_PATH="$INSTALL_DIR/$BINARY_NAME"
|
|
||||||
|
|
||||||
# The binary runs in a non-TTY context, so force color on.
|
# The binary runs in a non-TTY context, so force color on.
|
||||||
STATUSLINE_CMD="$BINARY_PATH --color=always"
|
STATUSLINE_CMD="$BINARY_PATH --color=always"
|
||||||
|
|
||||||
if [[ -f "$SETTINGS" ]]; then
|
if [[ -f "$SETTINGS" ]]; then
|
||||||
# Update existing settings.json
|
# Update existing settings.json, preserving all other keys
|
||||||
CURRENT_CMD=$(jq -r '.statusLine.command // empty' "$SETTINGS" 2>/dev/null || true)
|
CURRENT_CMD=$(jq -r '.statusLine.command // empty' "$SETTINGS" 2>/dev/null || true)
|
||||||
if [[ -n "$CURRENT_CMD" ]]; then
|
if [[ -n "$CURRENT_CMD" ]]; then
|
||||||
echo "[info] Current statusLine command: $CURRENT_CMD"
|
echo "[info] Previous statusLine command: $CURRENT_CMD"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Write updated settings
|
|
||||||
TMP="$SETTINGS.tmp.$$"
|
TMP="$SETTINGS.tmp.$$"
|
||||||
jq --arg cmd "$STATUSLINE_CMD" '.statusLine = {"type": "command", "command": $cmd, "padding": 0}' "$SETTINGS" > "$TMP"
|
if jq --arg cmd "$STATUSLINE_CMD" '.statusLine = {"type": "command", "command": $cmd, "padding": 0}' "$SETTINGS" > "$TMP" 2>/dev/null; then
|
||||||
mv "$TMP" "$SETTINGS"
|
mv "$TMP" "$SETTINGS"
|
||||||
echo "[ok] Updated statusLine in $SETTINGS"
|
echo "[ok] Updated statusLine in $SETTINGS"
|
||||||
|
else
|
||||||
|
rm -f "$TMP"
|
||||||
|
echo "[warn] Failed to update $SETTINGS (invalid JSON?). Creating backup and writing fresh."
|
||||||
|
cp "$SETTINGS" "$SETTINGS.bak"
|
||||||
|
jq -n --arg cmd "$STATUSLINE_CMD" '{"statusLine": {"type": "command", "command": $cmd, "padding": 0}}' > "$SETTINGS"
|
||||||
|
echo "[ok] Wrote fresh $SETTINGS (backup: $SETTINGS.bak)"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
# Create minimal settings.json
|
# Create minimal settings.json
|
||||||
jq -n --arg cmd "$STATUSLINE_CMD" '{"statusLine": {"type": "command", "command": $cmd, "padding": 0}}' > "$SETTINGS"
|
jq -n --arg cmd "$STATUSLINE_CMD" '{"statusLine": {"type": "command", "command": $cmd, "padding": 0}}' > "$SETTINGS"
|
||||||
echo "[ok] Created $SETTINGS"
|
echo "[ok] Created $SETTINGS"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Show what was written so the user can verify
|
||||||
|
echo ""
|
||||||
|
echo " statusLine config:"
|
||||||
|
jq '.statusLine' "$SETTINGS" 2>/dev/null || echo " (could not read settings)"
|
||||||
|
|
||||||
# ── Symlink config ───────────────────────────────────────────────────
|
# ── Symlink config ───────────────────────────────────────────────────
|
||||||
CONFIG_SRC="$SCRIPT_DIR/statusline.json"
|
CONFIG_SRC="$SCRIPT_DIR/statusline.json"
|
||||||
CONFIG_DST="$CLAUDE_DIR/statusline.json"
|
CONFIG_DST="$CLAUDE_DIR/statusline.json"
|
||||||
@@ -123,7 +141,8 @@ fi
|
|||||||
|
|
||||||
# ── Done ─────────────────────────────────────────────────────────────
|
# ── Done ─────────────────────────────────────────────────────────────
|
||||||
echo ""
|
echo ""
|
||||||
echo "Done. Restart Claude Code to see the status line."
|
echo "Done. RESTART Claude Code (exit and reopen) to see the status line."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Quick test: $BINARY_NAME --test --color=always"
|
echo "Verify: $BINARY_PATH --test --color=always"
|
||||||
echo "Debug: $BINARY_NAME --test --dump-state=json"
|
echo "Debug: $BINARY_PATH --test --dump-state=json"
|
||||||
|
echo "Settings: cat $SETTINGS | jq .statusLine"
|
||||||
|
|||||||
Reference in New Issue
Block a user