_default:
    @just --list

# Skills backed up in this repo, installed into ~/.claude/skills (repo -> ~/.claude)
skills := "sourcehut-ci sourcehut-custom-service"

# Absolute path to this repo (the SourceHut documentation mirror), substituted
# into skills for the __SRHT_MIRROR__ placeholder at install time.
mirror := justfile_directory()

# Install the backed-up skills into ~/.claude/skills
install:
    #!/usr/bin/env bash
    set -euo pipefail
    for skill in {{skills}}; do
        src="skills/$skill"
        dst="$HOME/.claude/skills/$skill"
        mkdir -p "$dst"
        rsync -a --delete --exclude='.*' "$src/" "$dst/"
        # Substitute the mirror-root placeholder with this repo's absolute path
        find "$dst" -type f -name '*.md' -print0 | while IFS= read -r -d '' f; do
            sed "s|__SRHT_MIRROR__|{{mirror}}|g" "$f" > "$f.tmp" && mv "$f.tmp" "$f"
        done
        echo "Installed $skill -> $dst ($(find "$dst" -type f | wc -l | tr -d ' ') files)"
    done
