Files
felhom.eu/scripts/install_skills.py
T

78 lines
2.8 KiB
Python

# -*- coding: utf-8 -*-
"""Install the Felhom Claude Code skills from <repo>/skills/ into ~/.claude/skills/.
Usage: python scripts/install_skills.py (run from the felhom.eu repo root or anywhere)
Personal skills (~/.claude/skills/) apply across all projects — the right scope for the 4-repo
E:\\git workspace. Preferred install is a Windows junction (mklink /J) so edits in the repo are live
immediately; if junction creation fails or isn't followed, falls back to a full COPY — in copy mode
you must RE-RUN this script after editing skills/. Idempotent: safe to re-run any time.
"""
import os, shutil, subprocess, sys
REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SRC = os.path.join(REPO, "skills")
DST = os.path.join(os.path.expanduser("~"), ".claude", "skills")
fails = 0
copy_mode_used = False
def is_working_junction(target, src):
"""True if target resolves into src (junction/symlink already correct)."""
try:
return os.path.isfile(os.path.join(target, "SKILL.md")) and \
os.path.samefile(os.path.join(target, "SKILL.md"), os.path.join(src, "SKILL.md"))
except OSError:
return False
def remove_existing(target):
# a junction must be removed with rmdir semantics (never recurse INTO it), a copy with rmtree
try:
os.rmdir(target) # works for junctions and empty dirs
except OSError:
shutil.rmtree(target, ignore_errors=True)
def install(name):
global fails, copy_mode_used
src = os.path.join(SRC, name)
target = os.path.join(DST, name)
if os.path.exists(target):
if is_working_junction(target, src):
print("OK %-22s junction (already installed, live-linked to repo)" % name)
return
remove_existing(target)
# try junction first
r = subprocess.run(["cmd", "/c", "mklink", "/J", target, src],
capture_output=True, text=True)
if r.returncode == 0 and is_working_junction(target, src):
print("OK %-22s junction -> %s" % (name, src))
return
# fall back to copy
if os.path.exists(target):
remove_existing(target)
try:
shutil.copytree(src, target)
copy_mode_used = True
print("OK %-22s COPY (junction failed: %s)" % (name, (r.stderr or r.stdout).strip() or "not followed"))
except OSError as e:
fails += 1
print("FAIL %-22s %s" % (name, e))
if not os.path.isdir(SRC):
print("FAIL: no skills/ dir at %s" % SRC)
sys.exit(2)
os.makedirs(DST, exist_ok=True)
names = sorted(d for d in os.listdir(SRC) if os.path.isfile(os.path.join(SRC, d, "SKILL.md")))
if not names:
print("FAIL: no skills found under %s" % SRC)
sys.exit(2)
for n in names:
install(n)
if copy_mode_used:
print("\nNOTE: copy mode active for at least one skill — RE-RUN this script after editing skills/.")
sys.exit(1 if fails else 0)