initialize-skills.sh 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. SKILLS_DIR="${HOME}/.config/superpowers/skills"
  4. SKILLS_REPO="https://github.com/obra/superpowers-skills.git"
  5. # Check if skills directory exists and is a valid git repo
  6. if [ -d "$SKILLS_DIR/.git" ]; then
  7. cd "$SKILLS_DIR"
  8. # Fetch upstream
  9. git fetch upstream 2>/dev/null || git fetch origin 2>/dev/null || true
  10. # Check if we can fast-forward
  11. LOCAL=$(git rev-parse @ 2>/dev/null || echo "")
  12. REMOTE=$(git rev-parse @{u} 2>/dev/null || echo "")
  13. BASE=$(git merge-base @ @{u} 2>/dev/null || echo "")
  14. if [ -n "$LOCAL" ] && [ -n "$REMOTE" ] && [ "$LOCAL" != "$REMOTE" ]; then
  15. # Check if we can fast-forward (local is ancestor of remote)
  16. if [ "$LOCAL" = "$BASE" ]; then
  17. # Fast-forward merge is possible
  18. git merge --ff-only @{u} 2>/dev/null && echo "✓ Skills updated to latest version" || true
  19. else
  20. # Can't fast-forward (diverged or local is ahead)
  21. echo "⚠️ New skills available from upstream. Ask me to use the pulling-updates-from-skills-repository skill."
  22. fi
  23. fi
  24. exit 0
  25. fi
  26. # Skills directory doesn't exist or isn't a git repo - initialize it
  27. echo "Initializing skills repository..."
  28. # Handle migration from old installation
  29. if [ -d "${HOME}/.config/superpowers/.git" ]; then
  30. echo "Found existing installation. Backing up..."
  31. mv "${HOME}/.config/superpowers/.git" "${HOME}/.config/superpowers/.git.bak"
  32. if [ -d "${HOME}/.config/superpowers/skills" ]; then
  33. mv "${HOME}/.config/superpowers/skills" "${HOME}/.config/superpowers/skills.bak"
  34. echo "Your old skills are in ~/.config/superpowers/skills.bak"
  35. fi
  36. fi
  37. # Clone the skills repository
  38. mkdir -p "${HOME}/.config/superpowers"
  39. git clone "$SKILLS_REPO" "$SKILLS_DIR"
  40. cd "$SKILLS_DIR"
  41. # Offer to fork if gh is installed
  42. if command -v gh &> /dev/null; then
  43. echo ""
  44. echo "GitHub CLI detected. Would you like to fork superpowers-skills?"
  45. echo "Forking allows you to share skill improvements with the community."
  46. echo ""
  47. read -p "Fork superpowers-skills? (y/N): " -n 1 -r
  48. echo
  49. if [[ $REPLY =~ ^[Yy]$ ]]; then
  50. gh repo fork obra/superpowers-skills --remote=true
  51. echo "Forked! You can now contribute skills back to the community."
  52. else
  53. git remote add upstream "$SKILLS_REPO"
  54. fi
  55. else
  56. # No gh, just set up upstream remote
  57. git remote add upstream "$SKILLS_REPO"
  58. fi
  59. echo "Skills repository initialized at $SKILLS_DIR"