-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·170 lines (147 loc) · 7.4 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·170 lines (147 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env bash
set -e
SKILLS=(eli5-mode eli-kid eli-teen eli-adult eli-expert eli-off eli-status eli-deeper eli-simpler eli-save eli-quiz eli-doc eli-pr eli-brief eli-commit eli-compare eli-prereqs eli-teach eli-recap eli-remember eli-tweet eli-tldr)
SKILLS_DIR="${HOME}/.claude/skills"
HOOKS_DIR="${HOME}/.claude/hooks"
CLAUDE_DIR="${HOME}/.claude"
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VERSION="$(cat "${REPO_DIR}/VERSION" 2>/dev/null || echo "?")"
# ── Colors ────────────────────────────────────────────────────────────────────
GREEN='\033[0;32m'; BLUE='\033[0;34m'; YELLOW='\033[1;33m'; RED='\033[0;31m'; BOLD='\033[1m'; NC='\033[0m'
info() { printf "${BLUE} →${NC} %s\n" "$*"; }
success() { printf "${GREEN} ✓${NC} %s\n" "$*"; }
warn() { printf "${YELLOW} !${NC} %s\n" "$*"; }
error() { printf "${RED} ✗${NC} %s\n" "$*"; exit 1; }
header() { printf "\n${BOLD}%s${NC}\n" "$*"; }
echo ""
printf "${BOLD} eli5-mode v${VERSION} installer${NC}\n"
echo " ──────────────────────────────"
echo ""
command -v claude >/dev/null 2>&1 || error "claude not found. Install Claude Code: https://claude.ai/code"
# ── Skills ────────────────────────────────────────────────────────────────────
header " Installing skills..."
mkdir -p "${SKILLS_DIR}"
for skill in "${SKILLS[@]}"; do
src="${REPO_DIR}/skills/${skill}"
dest="${SKILLS_DIR}/${skill}"
if [ ! -d "${src}" ]; then
warn "Skill source not found: ${src}"
continue
fi
[ -d "${dest}" ] && rm -rf "${dest}"
cp -r "${src}" "${dest}"
success "${skill}"
done
# ── Hooks ─────────────────────────────────────────────────────────────────────
header " Installing hooks..."
mkdir -p "${HOOKS_DIR}"
SESSION_HOOK_SRC="${REPO_DIR}/hooks/eli5-session-start.sh"
SESSION_HOOK_DEST="${HOOKS_DIR}/eli5-session-start.sh"
PER_TURN_SRC="${REPO_DIR}/hooks/eli5-per-turn.js"
PER_TURN_DEST="${HOOKS_DIR}/eli5-per-turn.js"
STATUSLINE_SRC="${REPO_DIR}/hooks/eli5-statusline.sh"
STATUSLINE_DEST="${HOOKS_DIR}/eli5-statusline.sh"
cp "${SESSION_HOOK_SRC}" "${SESSION_HOOK_DEST}" && chmod +x "${SESSION_HOOK_DEST}"
success "SessionStart → ${SESSION_HOOK_DEST}"
cp "${PER_TURN_SRC}" "${PER_TURN_DEST}"
success "UserPromptSubmit → ${PER_TURN_DEST}"
cp "${STATUSLINE_SRC}" "${STATUSLINE_DEST}" && chmod +x "${STATUSLINE_DEST}"
success "Statusline → ${STATUSLINE_DEST}"
# Register hooks in settings.json
SETTINGS="${CLAUDE_DIR}/settings.json"
if [ ! -f "${SETTINGS}" ]; then
echo '{}' > "${SETTINGS}"
fi
if command -v node >/dev/null 2>&1; then
node - "${SETTINGS}" "${SESSION_HOOK_DEST}" "${PER_TURN_DEST}" "${STATUSLINE_DEST}" <<'EOF'
const fs = require('fs');
const [,, sp, sessionHook, perTurnHook, statuslineHook] = process.argv;
let s = {};
try { s = JSON.parse(fs.readFileSync(sp, 'utf8')); } catch {}
s.hooks = s.hooks || {};
// SessionStart
s.hooks.SessionStart = s.hooks.SessionStart || [];
const sessionCmd = `bash "${sessionHook}"`;
if (!s.hooks.SessionStart.some(h => h.hooks?.some(hh => hh.command === sessionCmd))) {
s.hooks.SessionStart.push({ hooks: [{ type: 'command', command: sessionCmd }] });
}
// UserPromptSubmit (per-turn reinforcement)
s.hooks.UserPromptSubmit = s.hooks.UserPromptSubmit || [];
const perTurnCmd = `node "${perTurnHook}"`;
if (!s.hooks.UserPromptSubmit.some(h => h.hooks?.some(hh => hh.command === perTurnCmd))) {
s.hooks.UserPromptSubmit.push({ hooks: [{ type: 'command', command: perTurnCmd }] });
}
// Statusline — only set if not already configured
if (!s.statusLine) {
s.statusLine = { type: 'command', command: `bash "${statuslineHook}"` };
console.log('statusline_set');
} else {
console.log('statusline_skip');
}
fs.writeFileSync(sp, JSON.stringify(s, null, 2));
EOF
if [ $? -eq 0 ]; then
success "Registered SessionStart + UserPromptSubmit in settings.json"
# Check if statusline was set or skipped (last stdout line)
STATUSLINE_RESULT=$(node - "${SETTINGS}" "${STATUSLINE_DEST}" <<'JSEOF'
const fs = require('fs');
const [,, sp, sh] = process.argv;
const s = JSON.parse(fs.readFileSync(sp,'utf8'));
console.log(s.statusLine?.command?.includes('eli5-statusline') ? 'active' : 'other');
JSEOF
)
if [ "${STATUSLINE_RESULT}" = "active" ]; then
success "Statusline badge registered [ELI5] / [ELI5:TEEN] etc."
else
warn "Statusline already configured — add manually to settings.json if desired:"
warn " \"statusLine\": { \"type\": \"command\", \"command\": \"bash \\\"${STATUSLINE_DEST}\\\"\" }"
fi
fi
else
warn "Node.js not found — add hooks to settings.json manually (see examples/CLAUDE.md)"
fi
# ── CLAUDE.md patch ───────────────────────────────────────────────────────────
header " Patching ~/.claude/CLAUDE.md..."
GLOBAL_MD="${CLAUDE_DIR}/CLAUDE.md"
touch "${GLOBAL_MD}"
_append_block() {
{ echo ""; cat "${REPO_DIR}/examples/CLAUDE.md"; echo ""; } >> "${GLOBAL_MD}"
}
if grep -q "<!-- eli5-mode:end -->" "${GLOBAL_MD}" 2>/dev/null; then
# New-style versioned block exists — replace it
awk '/^<!-- eli5-mode:start -->/{skip=1; next} /^<!-- eli5-mode:end -->/{skip=0; next} !skip{print}' \
"${GLOBAL_MD}" > "${GLOBAL_MD}.tmp" && mv "${GLOBAL_MD}.tmp" "${GLOBAL_MD}"
_append_block
success "Updated CLAUDE.md block"
elif grep -q "# eli5-mode: auto-activation" "${GLOBAL_MD}" 2>/dev/null; then
# Old-style block (pre-v2) — find its start line and truncate, then append new
OLD_LINE=$(grep -n "# eli5-mode: auto-activation" "${GLOBAL_MD}" | head -1 | cut -d: -f1)
TRIM_TO=$(( OLD_LINE - 2 ))
[ "${TRIM_TO}" -lt 0 ] && TRIM_TO=0
head -n "${TRIM_TO}" "${GLOBAL_MD}" > "${GLOBAL_MD}.tmp" && mv "${GLOBAL_MD}.tmp" "${GLOBAL_MD}"
_append_block
success "Upgraded CLAUDE.md block (old → new)"
else
# Fresh install — append
_append_block
success "Patched CLAUDE.md"
fi
# ── Done ──────────────────────────────────────────────────────────────────────
echo ""
echo " ──────────────────────────────"
printf " ${GREEN}${BOLD}All done.${NC} Start a new Claude Code session.\n"
echo ""
echo " Activate: eli5 · ELI5 · /eli5 · dumb it down · explain simply"
echo " Levels: /eli-kid · /eli-teen · /eli-adult · /eli-expert"
echo " Navigate: /eli-deeper · /eli-simpler"
echo ""
echo " Learning: /eli-compare · /eli-prereqs · /eli-teach · /eli-quiz · /eli-recap"
echo " Formats: /eli-brief · /eli-tweet · /eli-tldr"
echo " Workflow: /eli-pr · /eli-commit"
echo " Memory: /eli-remember · /eli-save · /eli-doc [--team]"
echo ""
echo " Turn off: /eli-off · stop eli5 · normal mode"
echo ""
echo " Auto-activate: drop a .eli5rc in your project (see examples/eli5rc-example)"
echo " Passive mode: add passive_mode=true to .eli5rc for background jargon nudges"
echo ""