Fix CRLF line endings, harden install.sh

- Add .gitattributes enforcing LF line endings
- Renormalize all files from CRLF to LF
- Replace fragile sed-based JSON manipulation with node -e
- Add Node.js 18+ version check (required for built-in fetch)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Axel Meyer
2026-02-14 15:28:34 +00:00
parent ddd3b6d637
commit d152dde002
5 changed files with 290 additions and 284 deletions

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
* text=auto eol=lf

View File

@@ -8,6 +8,19 @@ INSTALL_DIR="${HOME}/.local/share/claude-statusline"
CONFIG_DIR="${HOME}/.config/claude-statusline" CONFIG_DIR="${HOME}/.config/claude-statusline"
CLAUDE_DIR="${HOME}/.claude" CLAUDE_DIR="${HOME}/.claude"
# --- Check Node.js version (need 18+ for built-in fetch) ---
NODE_BIN="$(which node 2>/dev/null || echo '')"
if [ -z "$NODE_BIN" ]; then
echo "ERROR: Node.js not found. Install Node.js 18+ first."
exit 1
fi
NODE_MAJOR=$("$NODE_BIN" -e "process.stdout.write(String(process.versions.node.split('.')[0]))")
if [ "$NODE_MAJOR" -lt 18 ]; then
echo "ERROR: Node.js $("$NODE_BIN" --version) found, but 18+ is required (built-in fetch)."
exit 1
fi
echo "==> Node.js v${NODE_MAJOR} found at $NODE_BIN"
echo "==> Installing claude-statusline..." echo "==> Installing claude-statusline..."
# Copy scripts # Copy scripts
@@ -27,28 +40,20 @@ fi
# Configure Claude Code statusline # Configure Claude Code statusline
mkdir -p "$CLAUDE_DIR" mkdir -p "$CLAUDE_DIR"
SETTINGS="$CLAUDE_DIR/settings.json" SETTINGS="$CLAUDE_DIR/settings.json"
NODE_BIN="$(which node 2>/dev/null || echo '/usr/bin/node')"
if [ -f "$SETTINGS" ]; then if [ -f "$SETTINGS" ]; then
# Check if statusLine already configured
if grep -q '"statusLine"' "$SETTINGS" 2>/dev/null; then if grep -q '"statusLine"' "$SETTINGS" 2>/dev/null; then
echo " statusLine already configured in $SETTINGS — skipping" echo " statusLine already configured in $SETTINGS — skipping"
else else
# Insert statusLine before last closing brace "$NODE_BIN" -e "
TMP=$(mktemp) const fs = require('fs');
sed '$ d' "$SETTINGS" > "$TMP" const settings = JSON.parse(fs.readFileSync('$SETTINGS', 'utf8'));
# Add comma if needed settings.statusLine = {
if grep -q '[^{]' "$TMP"; then type: 'command',
echo ',' >> "$TMP" command: '$NODE_BIN --no-warnings $INSTALL_DIR/statusline.js'
fi };
cat >> "$TMP" <<SEOF fs.writeFileSync('$SETTINGS', JSON.stringify(settings, null, 2) + '\n');
"statusLine": { "
"type": "command",
"command": "${NODE_BIN} --no-warnings ${INSTALL_DIR}/statusline.js"
}
}
SEOF
mv "$TMP" "$SETTINGS"
echo " Added statusLine to $SETTINGS" echo " Added statusLine to $SETTINGS"
fi fi
else else