openspec-zcode/install.sh

53 lines
1.6 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# install.sh — install OpenSpec skills + /opsx commands into ZCode user directory.
# Works on Linux, macOS, and Git Bash on Windows. Idempotent: safe to re-run.
set -euo pipefail
# Resolve repo root (directory of this script).
SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Target ZCode home (override with ZCODE_HOME if needed).
DEST="${ZCODE_HOME:-$HOME/.zcode}"
SKILLS_SRC="$SRC/skills"
COMMANDS_SRC="$SRC/commands/opsx"
SKILLS_DEST="$DEST/skills"
COMMANDS_DEST="$DEST/commands/opsx"
# Sanity checks.
if [ ! -d "$SKILLS_SRC" ]; then
echo "✗ Source skills directory not found at: $SKILLS_SRC" >&2
exit 1
fi
if [ ! -d "$COMMANDS_SRC" ]; then
echo "✗ Source commands directory not found at: $COMMANDS_SRC" >&2
exit 1
fi
# Create destination dirs.
mkdir -p "$SKILLS_DEST" "$COMMANDS_DEST"
# Copy each openspec-* skill directory, replacing if it already exists.
skill_count=0
for skill_dir in "$SKILLS_SRC"/openspec-*; do
[ -d "$skill_dir" ] || continue
name="$(basename "$skill_dir")"
rm -rf "$SKILLS_DEST/$name"
cp -r "$skill_dir" "$SKILLS_DEST/$name"
skill_count=$((skill_count + 1))
done
# Copy each /opsx command file.
cmd_count=0
for cmd_file in "$COMMANDS_SRC"/*.md; do
[ -f "$cmd_file" ] || continue
cp -f "$cmd_file" "$COMMANDS_DEST/"
cmd_count=$((cmd_count + 1))
done
echo "✓ Installed $skill_count skills + $cmd_count commands to $DEST"
echo " Skills: $SKILLS_DEST/openspec-*/SKILL.md"
echo " Commands: $COMMANDS_DEST/*.md → /opsx:<name>"
echo ""
echo "Restart ZCode (or start a new session) to pick up the new skills and commands."