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:
151
install.sh
151
install.sh
@@ -1,73 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
# Install claude-statusline for the current user.
|
||||
# Usage: bash install.sh
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
INSTALL_DIR="${HOME}/.local/share/claude-statusline"
|
||||
CONFIG_DIR="${HOME}/.config/claude-statusline"
|
||||
CLAUDE_DIR="${HOME}/.claude"
|
||||
|
||||
echo "==> Installing claude-statusline..."
|
||||
|
||||
# Copy scripts
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cp "$SCRIPT_DIR/statusline.js" "$INSTALL_DIR/"
|
||||
cp "$SCRIPT_DIR/fetch-usage.js" "$INSTALL_DIR/"
|
||||
chmod +x "$INSTALL_DIR"/*.js
|
||||
|
||||
# Create config dir
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
if [ ! -f "$CONFIG_DIR/session-key" ]; then
|
||||
echo "# Paste your claude.ai sessionKey cookie value here" > "$CONFIG_DIR/session-key"
|
||||
chmod 600 "$CONFIG_DIR/session-key"
|
||||
echo " Created $CONFIG_DIR/session-key (edit with your session key)"
|
||||
fi
|
||||
|
||||
# Configure Claude Code statusline
|
||||
mkdir -p "$CLAUDE_DIR"
|
||||
SETTINGS="$CLAUDE_DIR/settings.json"
|
||||
NODE_BIN="$(which node 2>/dev/null || echo '/usr/bin/node')"
|
||||
|
||||
if [ -f "$SETTINGS" ]; then
|
||||
# Check if statusLine already configured
|
||||
if grep -q '"statusLine"' "$SETTINGS" 2>/dev/null; then
|
||||
echo " statusLine already configured in $SETTINGS — skipping"
|
||||
else
|
||||
# Insert statusLine before last closing brace
|
||||
TMP=$(mktemp)
|
||||
sed '$ d' "$SETTINGS" > "$TMP"
|
||||
# Add comma if needed
|
||||
if grep -q '[^{]' "$TMP"; then
|
||||
echo ',' >> "$TMP"
|
||||
fi
|
||||
cat >> "$TMP" <<SEOF
|
||||
"statusLine": {
|
||||
"type": "command",
|
||||
"command": "${NODE_BIN} --no-warnings ${INSTALL_DIR}/statusline.js"
|
||||
}
|
||||
}
|
||||
SEOF
|
||||
mv "$TMP" "$SETTINGS"
|
||||
echo " Added statusLine to $SETTINGS"
|
||||
fi
|
||||
else
|
||||
cat > "$SETTINGS" <<SEOF
|
||||
{
|
||||
"statusLine": {
|
||||
"type": "command",
|
||||
"command": "${NODE_BIN} --no-warnings ${INSTALL_DIR}/statusline.js"
|
||||
}
|
||||
}
|
||||
SEOF
|
||||
echo " Created $SETTINGS with statusLine config"
|
||||
fi
|
||||
|
||||
# Offer cron setup
|
||||
echo ""
|
||||
echo "==> Optional: set up usage fetcher cron (every 5 min):"
|
||||
echo " crontab -e"
|
||||
echo " */5 * * * * ${NODE_BIN} ${INSTALL_DIR}/fetch-usage.js 2>/dev/null"
|
||||
echo ""
|
||||
echo "==> Done! Restart Claude Code to see the statusline."
|
||||
echo " Don't forget to add your session key to: $CONFIG_DIR/session-key"
|
||||
#!/usr/bin/env bash
|
||||
# Install claude-statusline for the current user.
|
||||
# Usage: bash install.sh
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
INSTALL_DIR="${HOME}/.local/share/claude-statusline"
|
||||
CONFIG_DIR="${HOME}/.config/claude-statusline"
|
||||
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..."
|
||||
|
||||
# Copy scripts
|
||||
mkdir -p "$INSTALL_DIR"
|
||||
cp "$SCRIPT_DIR/statusline.js" "$INSTALL_DIR/"
|
||||
cp "$SCRIPT_DIR/fetch-usage.js" "$INSTALL_DIR/"
|
||||
chmod +x "$INSTALL_DIR"/*.js
|
||||
|
||||
# Create config dir
|
||||
mkdir -p "$CONFIG_DIR"
|
||||
if [ ! -f "$CONFIG_DIR/session-key" ]; then
|
||||
echo "# Paste your claude.ai sessionKey cookie value here" > "$CONFIG_DIR/session-key"
|
||||
chmod 600 "$CONFIG_DIR/session-key"
|
||||
echo " Created $CONFIG_DIR/session-key (edit with your session key)"
|
||||
fi
|
||||
|
||||
# Configure Claude Code statusline
|
||||
mkdir -p "$CLAUDE_DIR"
|
||||
SETTINGS="$CLAUDE_DIR/settings.json"
|
||||
|
||||
if [ -f "$SETTINGS" ]; then
|
||||
if grep -q '"statusLine"' "$SETTINGS" 2>/dev/null; then
|
||||
echo " statusLine already configured in $SETTINGS — skipping"
|
||||
else
|
||||
"$NODE_BIN" -e "
|
||||
const fs = require('fs');
|
||||
const settings = JSON.parse(fs.readFileSync('$SETTINGS', 'utf8'));
|
||||
settings.statusLine = {
|
||||
type: 'command',
|
||||
command: '$NODE_BIN --no-warnings $INSTALL_DIR/statusline.js'
|
||||
};
|
||||
fs.writeFileSync('$SETTINGS', JSON.stringify(settings, null, 2) + '\n');
|
||||
"
|
||||
echo " Added statusLine to $SETTINGS"
|
||||
fi
|
||||
else
|
||||
cat > "$SETTINGS" <<SEOF
|
||||
{
|
||||
"statusLine": {
|
||||
"type": "command",
|
||||
"command": "${NODE_BIN} --no-warnings ${INSTALL_DIR}/statusline.js"
|
||||
}
|
||||
}
|
||||
SEOF
|
||||
echo " Created $SETTINGS with statusLine config"
|
||||
fi
|
||||
|
||||
# Offer cron setup
|
||||
echo ""
|
||||
echo "==> Optional: set up usage fetcher cron (every 5 min):"
|
||||
echo " crontab -e"
|
||||
echo " */5 * * * * ${NODE_BIN} ${INSTALL_DIR}/fetch-usage.js 2>/dev/null"
|
||||
echo ""
|
||||
echo "==> Done! Restart Claude Code to see the statusline."
|
||||
echo " Don't forget to add your session key to: $CONFIG_DIR/session-key"
|
||||
|
||||
Reference in New Issue
Block a user