80 lines
1.6 KiB
Bash
Executable File
80 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
skills_dir="${CODEX_SKILLS_DIR:-$HOME/.codex/skills}"
|
|
dry_run=0
|
|
|
|
usage() {
|
|
printf 'Usage: %s [--dry-run]\n' "$(basename "$0")"
|
|
printf 'Create symlinks for this repo'\''s skill directories in %s.\n' "$skills_dir"
|
|
}
|
|
|
|
case "${1:-}" in
|
|
"")
|
|
;;
|
|
--dry-run|-n)
|
|
dry_run=1
|
|
;;
|
|
--help|-h)
|
|
usage
|
|
exit 0
|
|
;;
|
|
*)
|
|
usage >&2
|
|
exit 2
|
|
;;
|
|
esac
|
|
|
|
run() {
|
|
if (( dry_run )); then
|
|
printf 'DRY RUN:'
|
|
printf ' %q' "$@"
|
|
printf '\n'
|
|
else
|
|
"$@"
|
|
fi
|
|
}
|
|
|
|
if (( dry_run )); then
|
|
printf 'DRY RUN: mkdir -p %q\n' "$skills_dir"
|
|
else
|
|
mkdir -p "$skills_dir"
|
|
fi
|
|
|
|
found=0
|
|
|
|
while IFS= read -r -d '' skill_file; do
|
|
found=1
|
|
skill_path="$(dirname "$skill_file")"
|
|
skill_name="$(basename "$skill_path")"
|
|
link_path="$skills_dir/$skill_name"
|
|
|
|
if [[ -L "$link_path" ]]; then
|
|
current_target="$(readlink "$link_path")"
|
|
if [[ "$current_target" == "$skill_path" ]]; then
|
|
printf 'Already linked: %s -> %s\n' "$link_path" "$skill_path"
|
|
else
|
|
printf 'Skipping existing symlink: %s -> %s\n' "$link_path" "$current_target"
|
|
fi
|
|
continue
|
|
fi
|
|
|
|
if [[ -e "$link_path" ]]; then
|
|
printf 'Skipping existing path: %s\n' "$link_path"
|
|
continue
|
|
fi
|
|
|
|
run ln -s "$skill_path" "$link_path"
|
|
if (( dry_run )); then
|
|
printf 'Would link: %s -> %s\n' "$link_path" "$skill_path"
|
|
else
|
|
printf 'Linked: %s -> %s\n' "$link_path" "$skill_path"
|
|
fi
|
|
done < <(find "$repo_root" -mindepth 2 -maxdepth 2 -name SKILL.md -print0 | sort -z)
|
|
|
|
if (( ! found )); then
|
|
printf 'No skill directories found under %s\n' "$repo_root" >&2
|
|
exit 1
|
|
fi
|