initialize-skills.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 (silently)
  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. # Try to fast-forward merge first
  15. if [ -n "$LOCAL" ] && [ -n "$REMOTE" ] && [ "$LOCAL" != "$REMOTE" ]; then
  16. # Check if we can fast-forward (local is ancestor of remote)
  17. if [ "$LOCAL" = "$BASE" ]; then
  18. # Fast-forward merge is possible
  19. echo "Updating skills to latest version..."
  20. if git merge --ff-only @{u} 2>&1; then
  21. echo "✓ Skills updated successfully"
  22. echo "SKILLS_UPDATED=true"
  23. else
  24. echo "Failed to update skills"
  25. fi
  26. else
  27. # Can't fast-forward - will be reported at the end
  28. echo "SKILLS_BEHIND=true"
  29. fi
  30. fi
  31. exit 0
  32. fi
  33. # Skills directory doesn't exist or isn't a git repo - initialize it
  34. echo "Initializing skills repository..."
  35. # Handle migration from old installation
  36. if [ -d "${HOME}/.config/superpowers/.git" ]; then
  37. echo "Found existing installation. Backing up..."
  38. mv "${HOME}/.config/superpowers/.git" "${HOME}/.config/superpowers/.git.bak"
  39. if [ -d "${HOME}/.config/superpowers/skills" ]; then
  40. mv "${HOME}/.config/superpowers/skills" "${HOME}/.config/superpowers/skills.bak"
  41. echo "Your old skills are in ~/.config/superpowers/skills.bak"
  42. fi
  43. fi
  44. # Clone the skills repository
  45. mkdir -p "${HOME}/.config/superpowers"
  46. git clone "$SKILLS_REPO" "$SKILLS_DIR"
  47. cd "$SKILLS_DIR"
  48. # Offer to fork if gh is installed
  49. if command -v gh &> /dev/null; then
  50. echo ""
  51. echo "GitHub CLI detected. Would you like to fork superpowers-skills?"
  52. echo "Forking allows you to share skill improvements with the community."
  53. echo ""
  54. read -p "Fork superpowers-skills? (y/N): " -n 1 -r
  55. echo
  56. if [[ $REPLY =~ ^[Yy]$ ]]; then
  57. gh repo fork obra/superpowers-skills --remote=true
  58. echo "Forked! You can now contribute skills back to the community."
  59. else
  60. git remote add upstream "$SKILLS_REPO"
  61. fi
  62. else
  63. # No gh, just set up upstream remote
  64. git remote add upstream "$SKILLS_REPO"
  65. fi
  66. echo "Skills repository initialized at $SKILLS_DIR"