#!/usr/bin/env sh set -eu # Install Codex skills from this Playbook snapshot into CODEX_HOME. # - Source: /codex/skills// # - Dest: $CODEX_HOME/skills// (default CODEX_HOME=~/.codex) # # Usage: # sh scripts/install_codex_skills.sh # install all skills # sh scripts/install_codex_skills.sh style-cleanup code-review-workflow # # Notes: # - Codex loads skills at startup; restart `codex` after installation. # - Existing destination skill dirs are backed up with a timestamp suffix. SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)" SRC="$(CDPATH= cd -- "$SCRIPT_DIR/.." && pwd -P)" SKILLS_SRC_ROOT="$SRC/codex/skills" CODEX_HOME="${CODEX_HOME:-$HOME/.codex}" SKILLS_DST_ROOT="$CODEX_HOME/skills" if [ ! -d "$SKILLS_SRC_ROOT" ]; then echo "ERROR: skills source dir not found: $SKILLS_SRC_ROOT" >&2 exit 1 fi mkdir -p "$SKILLS_DST_ROOT" timestamp="$(date +%Y%m%d%H%M%S 2>/dev/null || echo bak)" install_one() { name="$1" src_dir="$SKILLS_SRC_ROOT/$name" dst_dir="$SKILLS_DST_ROOT/$name" if [ ! -d "$src_dir" ]; then echo "ERROR: skill not found: $name ($src_dir)" >&2 exit 1 fi if [ -e "$dst_dir" ]; then mv "$dst_dir" "$SKILLS_DST_ROOT/$name.bak.$timestamp" echo "Backed up existing skill: $name -> $name.bak.$timestamp" fi cp -R "$src_dir" "$dst_dir" echo "Installed: $name" } if [ "$#" -gt 0 ]; then for name in "$@"; do install_one "$name" done else for dir in "$SKILLS_SRC_ROOT"/*; do [ -d "$dir" ] || continue name="$(basename -- "$dir")" case "$name" in ""|.*) continue ;; esac install_one "$name" done fi echo "Done. Skills installed to: $SKILLS_DST_ROOT"