-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinstall.sh
More file actions
299 lines (260 loc) · 7.47 KB
/
Copy pathinstall.sh
File metadata and controls
299 lines (260 loc) · 7.47 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#!/usr/bin/env bash
# tools-public installer — Claude Code slash commands from
# github.com/cppalliance/tools-public.
#
# Install:
# curl -fsSL https://raw.githubusercontent.com/cppalliance/tools-public/master/install.sh | bash
#
# Uninstall (removes the same set, leaves your own commands alone):
# curl -fsSL https://raw.githubusercontent.com/cppalliance/tools-public/master/uninstall.sh | bash
# # or:
# UNINSTALL=1 curl -fsSL https://raw.githubusercontent.com/cppalliance/tools-public/master/install.sh | bash
#
# Re-run install to update to the latest versions; existing files are overwritten.
# Env knobs:
# INSTALL_YES=1 skip the [y/N] confirmation
# UNINSTALL=1 remove instead of install
# DEST=/path override ~/.claude/commands
# LOCAL_SRC=/path use a local checkout instead of downloading the tarball
set -euo pipefail
REPO="cppalliance/tools-public"
BRANCH="master"
TARBALL_URL="https://github.com/${REPO}/archive/refs/heads/${BRANCH}.tar.gz"
DEST="${DEST:-${HOME}/.claude/commands}"
LOCAL_SRC="${LOCAL_SRC:-}"
# Mode: parse --uninstall flag or UNINSTALL env var.
MODE="install"
for arg in "$@"; do
case "$arg" in
--uninstall) MODE="uninstall" ;;
--help|-h)
sed -n '2,20p' "$0"
exit 0
;;
esac
done
[[ "${UNINSTALL:-}" == "1" ]] && MODE="uninstall"
TOP_LEVEL=(
advocatus.md
auditor.md
boost-review.md
btc-talk.md
code-cleanup.md
code-review.md
herald.md
is-this-cpp.md
lib-review.md
normalize.md
refine-plan.md
research.md
review-paper.md
tighten.md
)
FAMILIES=(voice interview tutor)
die() { echo "error: $*" >&2; exit 1; }
extract_description() {
local file="$1"
local desc=""
desc="$(awk '
BEGIN { in_fm = 0; line = 0 }
{ line++ }
line == 1 && /^---[[:space:]]*$/ { in_fm = 1; next }
in_fm && /^---[[:space:]]*$/ { exit }
in_fm && /^description:/ {
sub(/^description:[[:space:]]*/, "")
gsub(/^"|"$/, "")
print
exit
}
' "$file")"
if [[ -z "$desc" ]]; then
desc="$(awk '
BEGIN { seen = 0; in_comment = 0 }
/^#[^!]/ { seen = 1; next }
/<!--/ && !/-->/ { in_comment = 1; next }
in_comment && /-->/ { in_comment = 0; next }
in_comment { next }
/^<!--.*-->[[:space:]]*$/ { next }
seen && NF > 0 && !/^---/ && !/^```/ && !/^!\[/ && !/^\|/ { print; exit }
' "$file")"
fi
desc="${desc//\`/}"
desc="${desc//\*\*/}"
desc="$(printf '%s' "$desc" | awk '{
n = index($0, ". ")
if (n > 0 && n < 90) print substr($0, 1, n)
else print substr($0, 1, 90)
}')"
printf '%s' "$desc"
}
# NAMES[i] = slash-command name (with leading /)
# SOURCES[i] = path to source .md inside the extracted tree
# TARGETS[i] = absolute path under $DEST
plan() {
local src="$1"
NAMES=()
SOURCES=()
TARGETS=()
for f in "${TOP_LEVEL[@]}"; do
[[ -f "$src/$f" ]] || continue
NAMES+=("/${f%.md}")
SOURCES+=("$src/$f")
TARGETS+=("$DEST/$f")
done
for family in "${FAMILIES[@]}"; do
if [[ -f "$src/$family/$family.md" ]]; then
NAMES+=("/$family")
SOURCES+=("$src/$family/$family.md")
TARGETS+=("$DEST/$family.md")
fi
if [[ -d "$src/$family" ]]; then
for f in "$src/$family"/*.md; do
[[ -e "$f" ]] || continue
local base
base="$(basename "$f" .md)"
[[ "$base" == "$family" ]] && continue
NAMES+=("/$family:$base")
SOURCES+=("$f")
TARGETS+=("$DEST/$family/$base.md")
done
fi
done
}
print_banner() {
cat <<EOF
tools-public — Claude Code slash commands
==========================================
A curated set of prompt-based "tools" from github.com/cppalliance/tools-public.
Each command is a markdown prompt invoked via /<name> inside Claude Code,
covering code review, document tightening, plan refinement, persona voices,
adaptive interviews, tutorials, and more.
EOF
}
print_plan() {
local action_word="$1" # "install" or "remove"
local present_count=0
local i
for i in "${!TARGETS[@]}"; do
[[ -f "${TARGETS[$i]}" ]] && present_count=$((present_count + 1))
done
local max_width=0
for name in "${NAMES[@]}"; do
(( ${#name} > max_width )) && max_width=${#name}
done
if [[ "$action_word" == "install" ]]; then
echo "Will install ${#NAMES[@]} commands to $DEST"
if (( present_count > 0 )); then
echo "($present_count already present — those will be overwritten with the latest version.)"
fi
else
echo "Will remove ${present_count} commands from $DEST"
if (( present_count < ${#NAMES[@]} )); then
echo "($((${#NAMES[@]} - present_count)) listed below are not currently installed and will be skipped.)"
fi
fi
echo
for i in "${!NAMES[@]}"; do
local desc marker=" "
desc="$(extract_description "${SOURCES[$i]}")"
if [[ "$action_word" == "install" ]]; then
[[ -f "${TARGETS[$i]}" ]] && marker="↻" || marker="+"
else
[[ -f "${TARGETS[$i]}" ]] && marker="-" || marker=" "
fi
printf " %s %-${max_width}s %s\n" "$marker" "${NAMES[$i]}" "$desc"
done
echo
if [[ "$action_word" == "install" ]]; then
echo "Legend: + new ↻ overwrite (update)"
else
echo "Legend: - will be removed (blank) not installed, skipped"
fi
echo
}
confirm() {
local prompt="$1"
if [[ "${INSTALL_YES:-}" == "1" ]]; then
return 0
fi
if [[ ! -e /dev/tty ]]; then
die "no tty for confirmation; re-run with INSTALL_YES=1 to skip the prompt"
fi
local answer
read -r -p "$prompt [y/N] " answer </dev/tty
[[ "$answer" =~ ^[Yy]$ ]]
}
do_install() {
mkdir -p "$DEST"
local i count=0
for i in "${!TARGETS[@]}"; do
local target="${TARGETS[$i]}"
mkdir -p "$(dirname "$target")"
cp "${SOURCES[$i]}" "$target"
count=$((count + 1))
done
echo "Installed $count commands to $DEST."
echo "Restart Claude Code to pick them up."
}
do_uninstall() {
local i removed=0 skipped=0
for i in "${!TARGETS[@]}"; do
local target="${TARGETS[$i]}"
if [[ -f "$target" ]]; then
rm -f "$target"
removed=$((removed + 1))
else
skipped=$((skipped + 1))
fi
done
# Drop empty family subdirs we may have created.
for family in "${FAMILIES[@]}"; do
if [[ -d "$DEST/$family" ]]; then
rmdir "$DEST/$family" 2>/dev/null || true
fi
done
echo "Removed $removed commands from $DEST."
(( skipped > 0 )) && echo "Skipped $skipped (not currently installed)."
}
acquire_source() {
if [[ -n "$LOCAL_SRC" ]]; then
SRC="$LOCAL_SRC/tools"
[[ -d "$SRC" ]] || die "LOCAL_SRC=$LOCAL_SRC has no tools/ subdirectory"
echo "Source: local checkout at $LOCAL_SRC"
return
fi
command -v curl >/dev/null || die "curl is required"
command -v tar >/dev/null || die "tar is required"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
echo "Source: downloading ${REPO}@${BRANCH}..."
curl -fsSL "$TARBALL_URL" | tar -xz -C "$TMP"
SRC="$(find "$TMP" -maxdepth 2 -type d -name tools | head -n 1)"
[[ -n "$SRC" && -d "$SRC" ]] || die "could not locate tools/ in extracted tarball"
}
main() {
print_banner
echo "Mode: $MODE"
echo "Target: $DEST"
acquire_source
plan "$SRC"
[[ ${#NAMES[@]} -gt 0 ]] || die "nothing to process"
echo
if [[ "$MODE" == "install" ]]; then
print_plan "install"
if confirm "Proceed with install?"; then
do_install
else
echo "Aborted. Nothing installed."
exit 1
fi
else
print_plan "remove"
if confirm "Proceed with uninstall?"; then
do_uninstall
else
echo "Aborted. Nothing removed."
exit 1
fi
fi
}
main "$@"