gitlink-cli/scripts/setup-skills.sh

80 lines
2.3 KiB
Bash
Executable File

#!/bin/bash
# Link skills/gitlink-* into ~/.claude/skills/ so Claude Code can load and
# invoke them through the Skill tool (e.g. `Skill gitlink-issue`).
#
# Cross-platform:
# - Windows (Git Bash / MSYS): directory junction (mklink /J, no admin needed)
# - macOS / Linux: symlink
#
# Links point at the in-repo skills/ directory, so updating the repo keeps the
# Skill content in sync. The script is idempotent and safe to re-run.
#
# CRITICAL (Windows): an existing link is removed with `rmdir` (no /s), never
# `rm -rf` — `rm -rf` would follow the junction and DELETE THE SOURCE FILES.
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
SRC="$PROJECT_DIR/skills"
DST="$HOME/.claude/skills"
# --- collect gitlink-* skills ---
shopt -s nullglob
SKILLS=("$SRC"/gitlink-*/)
shopt -u nullglob
if [ ${#SKILLS[@]} -eq 0 ]; then
echo "No gitlink-* skills found under $SRC" >&2
exit 1
fi
mkdir -p "$DST"
# --- detect platform ---
case "$(uname -s)" in
MINGW*|MSYS*|CYGWIN*) PLATFORM=windows ;;
*) PLATFORM=unix ;;
esac
OK=0
FAIL=0
for skill in "${SKILLS[@]}"; do
skill="${skill%/}" # strip trailing slash for clean paths
name="$(basename "$skill")"
link="$DST/$name"
if [ "$PLATFORM" = "windows" ]; then
win_link="$(cygpath -w "$link")"
win_src="$(cygpath -w "$skill")"
if [ -e "$link" ] || [ -L "$link" ]; then
# rmdir (no /s) removes only the junction/symlink, never the target.
if ! cmd //c rmdir "$win_link" >/dev/null 2>&1; then
echo "SKIP $name (existing path is not a link — left untouched)"
FAIL=$((FAIL+1)); continue
fi
fi
if powershell -NoProfile -Command \
"New-Item -ItemType Junction -Path '$win_link' -Target '$win_src' -ErrorAction Stop" \
>/dev/null 2>&1; then
echo "OK $name"; OK=$((OK+1))
else
echo "FAIL $name"; FAIL=$((FAIL+1))
fi
else
# ln -sfn replaces an existing symlink safely (does not follow it).
if ln -sfn "$skill" "$link"; then
echo "OK $name"; OK=$((OK+1))
else
echo "FAIL $name"; FAIL=$((FAIL+1))
fi
fi
done
echo ""
echo "Done: $OK linked, $FAIL failed."
echo "Target: $DST"
echo "Skills are now invocable via the Claude Code Skill tool."