-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·522 lines (460 loc) · 17.5 KB
/
install.sh
File metadata and controls
executable file
·522 lines (460 loc) · 17.5 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
#!/usr/bin/env bash
set -euo pipefail
# ─── ANSI colors (with dumb-terminal fallback) ─────────────────────────────
if [[ "${TERM:-dumb}" != "dumb" ]] && command -v tput &>/dev/null && tput colors &>/dev/null; then
BOLD=$(tput bold) DIM=$(tput dim) RESET=$(tput sgr0)
GREEN=$(tput setaf 2) CYAN=$(tput setaf 6) YELLOW=$(tput setaf 3) RED=$(tput setaf 1)
else
BOLD="" DIM="" RESET="" GREEN="" CYAN="" YELLOW="" RED=""
fi
# ─── Restore terminal on unexpected exit ────────────────────────────────────
cleanup() { stty echo icanon 2>/dev/null || true; tput cnorm 2>/dev/null || true; }
trap cleanup EXIT
# ─── Globals ────────────────────────────────────────────────────────────────
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OS=""
SKILLS=() # discovered skill folder names
SKILL_DESCS=() # one-line descriptions (from frontmatter)
SKILL_SEL=() # 1/0 toggle per skill
TOOLS=("Claude Code" "Cursor" "Windsurf" "GitHub Copilot" "OpenAI Codex" "OpenCode" "Google Antigravity")
TOOL_SEL=() # 1/0 toggle per tool
INSTALL_SCOPE="" # "global" or "project"
INSTALLED=() # log: "skill → tool → path"
INSTALL_ALL_TOOLS=0 # 1 if "Install All" was toggled for tools
# ─── OS detection ───────────────────────────────────────────────────────────
detect_os() {
case "$(uname -s)" in
Darwin*) OS="macOS" ;;
Linux*)
if grep -qiE 'microsoft|wsl' /proc/version 2>/dev/null; then
OS="WSL"
else
OS="Linux"
fi ;;
CYGWIN*|MINGW*|MSYS*) OS="Windows" ;;
*) OS="Unknown" ;;
esac
}
# ─── Discover skills (folders containing SKILL.md) ─────────────────────────
discover_skills() {
local dir desc
for dir in "$SCRIPT_DIR"/skills/*/; do
[[ -f "$dir/SKILL.md" ]] || continue
local name
name="$(basename "$dir")"
# Extract description from YAML frontmatter (awk for macOS/Linux compat)
desc=$(awk '/^---$/{n++; next} n==1 && /^description:/{sub(/^description: *"?/, ""); sub(/"$/, ""); print; exit}' "$dir/SKILL.md")
# Truncate long descriptions for display
if [[ ${#desc} -gt 70 ]]; then
desc="${desc:0:67}..."
fi
SKILLS+=("$name")
SKILL_DESCS+=("$desc")
SKILL_SEL+=(0)
done
if [[ ${#SKILLS[@]} -eq 0 ]]; then
echo "${RED}No skills found (no subdirectories with SKILL.md in skills/).${RESET}"
exit 1
fi
}
# ─── Interactive checkbox list (Bash 3.2 compatible) ────────────────────────
# Usage: checkbox_select <title> <items_array_name> <descs_array_name> <selection_array_name>
# Modifies the selection array in-place (0/1 values) via eval.
checkbox_select() {
local title="$1"
local items_name=$2
local descs_name=$3
local sel_name=$4
eval "local count=\${#${items_name}[@]}"
local cursor=0
# Hide cursor, enable raw input
tput civis 2>/dev/null || true
stty -echo -icanon min 1 time 0 2>/dev/null || true
while true; do
# Draw the list
printf "\033[2J\033[H" # clear screen, move to top
echo "${BOLD}${CYAN}$title${RESET}"
echo "${DIM} ↑/↓ Navigate Space Toggle Enter Confirm${RESET}"
echo ""
local i
for (( i = 0; i < count; i++ )); do
local marker=" "
eval "local sel_val=\${${sel_name}[$i]}"
eval "local item_val=\"\${${items_name}[$i]}\""
eval "local desc_val=\"\${${descs_name}[$i]:-}\""
[[ "$sel_val" -eq 1 ]] && marker="${GREEN}✔${RESET} "
if [[ $i -eq $cursor ]]; then
printf " ${BOLD}▸ %s %-25s${RESET} ${DIM}%s${RESET}\n" "$marker" "$item_val" "$desc_val"
else
printf " %s %-25s ${DIM}%s${RESET}\n" "$marker" "$item_val" "$desc_val"
fi
done
# Read a keypress
local key
key=$(dd bs=1 count=1 2>/dev/null) || true
if [[ "$key" == $'\x1b' ]]; then
local seq
seq=$(dd bs=1 count=2 2>/dev/null) || true
case "$seq" in
'[A') [[ $cursor -gt 0 ]] && (( cursor-- )) || true ;; # Up
'[B') [[ $cursor -lt $((count - 1)) ]] && (( cursor++ )) || true ;; # Down
esac
elif [[ "$key" == " " ]]; then
# Toggle
eval "local cur_val=\${${sel_name}[$cursor]}"
if [[ "$cur_val" -eq 0 ]]; then
eval "${sel_name}[$cursor]=1"
else
eval "${sel_name}[$cursor]=0"
fi
elif [[ "$key" == "" ]]; then
# Enter
break
fi
done
# Restore terminal
stty echo icanon 2>/dev/null || true
tput cnorm 2>/dev/null || true
}
# ─── Interactive single-choice selector ──────────────────────────────────────
# Usage: radio_select <title> <items_array_name> <descs_array_name> <result_var_name>
# Sets the result variable to the selected index.
radio_select() {
local title="$1"
local items_name=$2
local descs_name=$3
local result_name=$4
eval "local count=\${#${items_name}[@]}"
local cursor=0
tput civis 2>/dev/null || true
stty -echo -icanon min 1 time 0 2>/dev/null || true
while true; do
printf "\033[2J\033[H"
echo "${BOLD}${CYAN}$title${RESET}"
echo "${DIM} ↑/↓ Navigate Enter Select${RESET}"
echo ""
local i
for (( i = 0; i < count; i++ )); do
eval "local item_val=\"\${${items_name}[$i]}\""
eval "local desc_val=\"\${${descs_name}[$i]:-}\""
local marker=" "
[[ $i -eq $cursor ]] && marker="${GREEN}●${RESET} "
if [[ $i -eq $cursor ]]; then
printf " ${BOLD}▸ %s %-25s${RESET} ${DIM}%s${RESET}\n" "$marker" "$item_val" "$desc_val"
else
printf " %s %-25s ${DIM}%s${RESET}\n" "$marker" "$item_val" "$desc_val"
fi
done
local key
key=$(dd bs=1 count=1 2>/dev/null) || true
if [[ "$key" == $'\x1b' ]]; then
local seq
seq=$(dd bs=1 count=2 2>/dev/null) || true
case "$seq" in
'[A') [[ $cursor -gt 0 ]] && (( cursor-- )) || true ;;
'[B') [[ $cursor -lt $((count - 1)) ]] && (( cursor++ )) || true ;;
esac
elif [[ "$key" == "" ]]; then
break
fi
done
stty echo icanon 2>/dev/null || true
tput cnorm 2>/dev/null || true
eval "${result_name}=${cursor}"
}
# ─── Strip YAML frontmatter from SKILL.md ──────────────────────────────────
strip_frontmatter() {
local file="$1"
awk 'BEGIN{n=0} /^---$/{n++; next} n>=2{print}' "$file"
}
# ─── Install one skill for one tool ────────────────────────────────────────
install_skill_for_tool() {
local skill="$1" tool="$2"
local src="$SCRIPT_DIR/skills/$skill"
local skill_dir dest_file
case "$tool" in
"Claude Code")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.claude/skills/$skill"
else
skill_dir=".claude/skills/$skill"
fi
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
INSTALLED+=("${skill}|${tool}|${skill_dir}/")
;;
"Cursor")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.agents/skills/$skill"
else
skill_dir=".agents/skills/$skill"
fi
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
mkdir -p .cursor/rules
dest_file=".cursor/rules/${skill}.mdc"
strip_frontmatter "$src/SKILL.md" > "$dest_file"
INSTALLED+=("${skill}|${tool}|${skill_dir}/ + ${dest_file}")
;;
"Windsurf")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.agents/skills/$skill"
else
skill_dir=".agents/skills/$skill"
fi
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
mkdir -p .windsurf/rules
dest_file=".windsurf/rules/${skill}.md"
strip_frontmatter "$src/SKILL.md" > "$dest_file"
INSTALLED+=("${skill}|${tool}|${skill_dir}/ + ${dest_file}")
;;
"GitHub Copilot")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.agents/skills/$skill"
else
skill_dir=".agents/skills/$skill"
fi
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
mkdir -p .github/instructions
dest_file=".github/instructions/${skill}.instructions.md"
strip_frontmatter "$src/SKILL.md" > "$dest_file"
INSTALLED+=("${skill}|${tool}|${skill_dir}/ + ${dest_file}")
;;
"OpenAI Codex")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.agents/skills/$skill"
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
mkdir -p "$HOME/.codex"
dest_file="$HOME/.codex/AGENTS.md"
else
skill_dir=".agents/skills/$skill"
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
dest_file="AGENTS.md"
fi
{
echo ""
echo "<!-- pskills: $skill -->"
strip_frontmatter "$src/SKILL.md"
echo "<!-- /pskills: $skill -->"
} >> "$dest_file"
INSTALLED+=("${skill}|${tool}|${skill_dir}/ + ${dest_file}")
;;
"OpenCode")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.agents/skills/$skill"
else
skill_dir=".agents/skills/$skill"
fi
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
INSTALLED+=("${skill}|${tool}|${skill_dir}/")
;;
"Google Antigravity")
if [[ "$INSTALL_SCOPE" == "global" ]]; then
skill_dir="$HOME/.agents/skills/$skill"
else
skill_dir=".agents/skills/$skill"
fi
mkdir -p "$skill_dir"
cp -r "$src"/* "$skill_dir"/
INSTALLED+=("${skill}|${tool}|${skill_dir}/")
;;
esac
}
# ─── Install one skill for ALL tools (shared .agents/skills + symlink) ────
install_skill_all_tools() {
local skill="$1"
local src="$SCRIPT_DIR/skills/$skill"
local shared_dir dest_file
# Step 1: Copy skill files to the shared canonical location (.agents/skills/)
if [[ "$INSTALL_SCOPE" == "global" ]]; then
shared_dir="$HOME/.agents/skills/$skill"
else
shared_dir=".agents/skills/$skill"
fi
mkdir -p "$shared_dir"
cp -r "$src"/* "$shared_dir"/
# Step 2: Create symlink for Claude Code
local claude_dir
if [[ "$INSTALL_SCOPE" == "global" ]]; then
claude_dir="$HOME/.claude/skills/$skill"
mkdir -p "$(dirname "$claude_dir")"
rm -rf "$claude_dir"
ln -s "$shared_dir" "$claude_dir"
else
claude_dir=".claude/skills/$skill"
mkdir -p "$(dirname "$claude_dir")"
rm -rf "$claude_dir"
ln -s "../../.agents/skills/$skill" "$claude_dir"
fi
INSTALLED+=("${skill}|Claude Code|${claude_dir}/ → ${shared_dir}/ (symlink)")
# Step 3: Cursor rule file
mkdir -p .cursor/rules
dest_file=".cursor/rules/${skill}.mdc"
strip_frontmatter "$src/SKILL.md" > "$dest_file"
INSTALLED+=("${skill}|Cursor|${shared_dir}/ + ${dest_file}")
# Step 4: Windsurf rule file
mkdir -p .windsurf/rules
dest_file=".windsurf/rules/${skill}.md"
strip_frontmatter "$src/SKILL.md" > "$dest_file"
INSTALLED+=("${skill}|Windsurf|${shared_dir}/ + ${dest_file}")
# Step 5: GitHub Copilot instructions file
mkdir -p .github/instructions
dest_file=".github/instructions/${skill}.instructions.md"
strip_frontmatter "$src/SKILL.md" > "$dest_file"
INSTALLED+=("${skill}|GitHub Copilot|${shared_dir}/ + ${dest_file}")
# Step 6: OpenAI Codex AGENTS.md entry
if [[ "$INSTALL_SCOPE" == "global" ]]; then
mkdir -p "$HOME/.codex"
dest_file="$HOME/.codex/AGENTS.md"
else
dest_file="AGENTS.md"
fi
{
echo ""
echo "<!-- pskills: $skill -->"
strip_frontmatter "$src/SKILL.md"
echo "<!-- /pskills: $skill -->"
} >> "$dest_file"
INSTALLED+=("${skill}|OpenAI Codex|${shared_dir}/ + ${dest_file}")
# Step 7: OpenCode (uses .agents/skills/ directly)
INSTALLED+=("${skill}|OpenCode|${shared_dir}/")
# Step 8: Google Antigravity (uses .agents/skills/ directly)
INSTALLED+=("${skill}|Google Antigravity|${shared_dir}/")
}
# ─── Print summary table ───────────────────────────────────────────────────
print_summary() {
if [[ ${#INSTALLED[@]} -eq 0 ]]; then
echo "${YELLOW}Nothing was installed.${RESET}"
return
fi
echo ""
echo "${BOLD}${GREEN}Installation Summary${RESET}"
echo ""
printf " ${BOLD}%-25s %-20s %s${RESET}\n" "Skill" "Tool" "Path"
printf " %-25s %-20s %s\n" "─────────────────────────" "────────────────────" "──────────────────────────────"
local entry
for entry in "${INSTALLED[@]}"; do
IFS='|' read -r s t p <<< "$entry"
printf " %-25s %-20s %s\n" "$s" "$t" "$p"
done
echo ""
}
# ─── Main ───────────────────────────────────────────────────────────────────
main() {
detect_os
echo "${BOLD}${CYAN}"
echo " ┌─────────────────────────────────────┐"
echo " │ pskills installer │"
echo " └─────────────────────────────────────┘${RESET}"
echo ""
echo " OS detected: ${BOLD}${OS}${RESET}"
echo ""
# Discover available skills
discover_skills
# ── Step 1: Select skills ──
# Build tool descriptions for display (empty — tools have no extra desc)
local TOOL_DESCS=()
TOOL_DESCS+=("~/.claude/skills/")
TOOL_DESCS+=("~/.agents/skills/ + .cursor/rules/")
TOOL_DESCS+=("~/.agents/skills/ + .windsurf/rules/")
TOOL_DESCS+=("~/.agents/skills/ + .github/instructions/")
TOOL_DESCS+=("~/.agents/skills/ + ~/.codex/AGENTS.md")
TOOL_DESCS+=("~/.agents/skills/")
TOOL_DESCS+=("~/.agents/skills/")
# Initialise tool selection array
for (( i = 0; i < ${#TOOLS[@]}; i++ )); do
TOOL_SEL+=(0)
done
# Prepend "Install All" option
local ALL_SKILLS=("Install All" "${SKILLS[@]}")
local ALL_SKILL_DESCS=("Select/deselect all skills at once" "${SKILL_DESCS[@]}")
local ALL_SKILL_SEL=(0)
for (( i = 0; i < ${#SKILLS[@]}; i++ )); do
ALL_SKILL_SEL+=(0)
done
checkbox_select "Select skills to install:" ALL_SKILLS ALL_SKILL_DESCS ALL_SKILL_SEL
# If "Install All" was toggled on, select every skill
if [[ ${ALL_SKILL_SEL[0]} -eq 1 ]]; then
for (( i = 0; i < ${#SKILLS[@]}; i++ )); do
SKILL_SEL[$i]=1
done
else
# Copy individual selections back (skip index 0 which is "Install All")
for (( i = 0; i < ${#SKILLS[@]}; i++ )); do
SKILL_SEL[$i]=${ALL_SKILL_SEL[$((i + 1))]}
done
fi
# Check if any skills were selected
local any_skill=0
for s in "${SKILL_SEL[@]}"; do [[ $s -eq 1 ]] && any_skill=1 && break; done
if [[ $any_skill -eq 0 ]]; then
printf "\033[2J\033[H"
echo "${YELLOW}No skills selected — exiting.${RESET}"
exit 0
fi
# ── Step 2: Select tools ──
# Prepend "Install All" option for tools
local ALL_TOOLS=("Install All" "${TOOLS[@]}")
local ALL_TOOL_DESCS=("Select all tools (shared .agents/skills/ + symlinks)" "${TOOL_DESCS[@]}")
local ALL_TOOL_SEL=(0)
for (( i = 0; i < ${#TOOLS[@]}; i++ )); do
ALL_TOOL_SEL+=(0)
done
checkbox_select "Select target tools:" ALL_TOOLS ALL_TOOL_DESCS ALL_TOOL_SEL
# If "Install All" was toggled on, select every tool and set flag
if [[ ${ALL_TOOL_SEL[0]} -eq 1 ]]; then
INSTALL_ALL_TOOLS=1
for (( i = 0; i < ${#TOOLS[@]}; i++ )); do
TOOL_SEL[$i]=1
done
else
# Copy individual selections back (skip index 0 which is "Install All")
for (( i = 0; i < ${#TOOLS[@]}; i++ )); do
TOOL_SEL[$i]=${ALL_TOOL_SEL[$((i + 1))]}
done
fi
local any_tool=0
for t in "${TOOL_SEL[@]}"; do [[ $t -eq 1 ]] && any_tool=1 && break; done
if [[ $any_tool -eq 0 ]]; then
printf "\033[2J\033[H"
echo "${YELLOW}No tools selected — exiting.${RESET}"
exit 0
fi
# ── Step 3: Select installation scope ──
local SCOPE_ITEMS=("Global" "Project")
local SCOPE_DESCS=("Install to ~/ (available in all projects)" "Install to ./ (current project only)")
local SCOPE_CHOICE=0
radio_select "Install scope:" SCOPE_ITEMS SCOPE_DESCS SCOPE_CHOICE
if [[ $SCOPE_CHOICE -eq 0 ]]; then
INSTALL_SCOPE="global"
else
INSTALL_SCOPE="project"
fi
# ── Step 4: Install ──
printf "\033[2J\033[H"
echo "${BOLD}${CYAN}Installing (${INSTALL_SCOPE})...${RESET}"
echo ""
local i j
for (( i = 0; i < ${#SKILLS[@]}; i++ )); do
[[ ${SKILL_SEL[$i]} -eq 0 ]] && continue
if [[ $INSTALL_ALL_TOOLS -eq 1 ]]; then
echo " ${GREEN}✔${RESET} ${BOLD}${SKILLS[$i]}${RESET} → All tools (shared + symlinks)"
install_skill_all_tools "${SKILLS[$i]}"
else
for (( j = 0; j < ${#TOOLS[@]}; j++ )); do
[[ ${TOOL_SEL[$j]} -eq 0 ]] && continue
echo " ${GREEN}✔${RESET} ${BOLD}${SKILLS[$i]}${RESET} → ${TOOLS[$j]}"
install_skill_for_tool "${SKILLS[$i]}" "${TOOLS[$j]}"
done
fi
done
# ── Step 5: Summary ──
print_summary
echo "${GREEN}Done!${RESET}"
}
main "$@"