link.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env bash
  2. # Symlink this repo into ~/.claude/
  3. # Run once after cloning on a new machine.
  4. set -euo pipefail
  5. REPO="$(cd "$(dirname "$0")" && pwd)"
  6. CLAUDE="$HOME/.claude"
  7. mkdir -p "$CLAUDE"
  8. # Core config files (plain files — ln -sf handles these correctly)
  9. ln -sf "$REPO/CLAUDE.md" "$CLAUDE/CLAUDE.md"
  10. ln -sf "$REPO/settings.json" "$CLAUDE/settings.json"
  11. # Agents and skills — must handle the case where target exists
  12. # as a real directory (ln -sf would create a link INSIDE the dir
  13. # instead of replacing it)
  14. for item in agents skills lib; do
  15. target="$CLAUDE/$item"
  16. if [ -L "$target" ]; then
  17. # Stale symlink from a previous run — remove before recreating
  18. rm -f "$target"
  19. elif [ -d "$target" ]; then
  20. echo "⚠️ ~/.claude/$item is a real directory (not a symlink)."
  21. echo " Rename or remove it, then re-run link.sh."
  22. echo " Skipping $item to avoid data loss."
  23. continue
  24. fi
  25. ln -sf "$REPO/$item" "$target"
  26. done
  27. # Hooks
  28. mkdir -p "$CLAUDE/hooks"
  29. ln -sf "$REPO/hooks/session-start.sh" "$CLAUDE/hooks/session-start.sh"
  30. # GStack (submodule) — symlink into ~/.claude/skills/ (which points to repo/skills/)
  31. # The submodule must be initialized first (done by install-plugins.sh)
  32. if [ -d "$REPO/skills-external/gstack" ]; then
  33. ln -sf "$REPO/skills-external/gstack" "$CLAUDE/skills/gstack"
  34. echo "✅ GStack symlinked from submodule"
  35. else
  36. echo "⚠️ GStack submodule not found — run: git submodule update --init"
  37. fi
  38. echo "✅ Symlinks created in ~/.claude/"
  39. echo " Next: bash install-plugins.sh"