diff options
Diffstat (limited to 'hooks')
| -rwxr-xr-x | hooks/session-start.sh | 28 | ||||
| -rwxr-xr-x | hooks/setup-personal-superpowers.sh | 52 |
2 files changed, 77 insertions, 3 deletions
diff --git a/hooks/session-start.sh b/hooks/session-start.sh index f6c4f11..27bb78a 100755 --- a/hooks/session-start.sh +++ b/hooks/session-start.sh @@ -1,15 +1,37 @@ #!/usr/bin/env bash # SessionStart hook for superpowers plugin -# Create data directory -mkdir -p ~/.superpowers +set -euo pipefail + +# Run personal superpowers setup +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +setup_output=$("${SCRIPT_DIR}/setup-personal-superpowers.sh" 2>&1 || echo "setup_failed=true") + +# Use same directory resolution as setup script +SUPERPOWERS_DIR="${PERSONAL_SUPERPOWERS_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/superpowers}" + +# Check if GitHub CLI is available and setup succeeded +github_recommendation="" +if echo "$setup_output" | grep -q "github_cli_available=true"; then + if [[ ! -d "$SUPERPOWERS_DIR/.git" ]]; then + # This should not happen, but handle gracefully + github_recommendation="" + else + # Check if remote already exists + if ! (cd "$SUPERPOWERS_DIR" && git remote get-url origin &>/dev/null); then + github_recommendation="\n\n💡 Want to share your personal skills on GitHub? Superpowers are best when everyone can learn from them! I can create a 'personal-superpowers' repo for you." + fi + fi +elif echo "$setup_output" | grep -q "setup_failed=true"; then + github_recommendation="\n\n⚠️ Personal superpowers setup encountered an issue. Please file a bug at https://github.com/obra/superpowers/issues" +fi # Output context injection as JSON cat <<EOF { "hookSpecificOutput": { "hookEventName": "SessionStart", - "additionalContext": "<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**RIGHT NOW, go read**: @${CLAUDE_PLUGIN_ROOT}/skills/getting-started/SKILL.md\n</EXTREMELY_IMPORTANT>" + "additionalContext": "<EXTREMELY_IMPORTANT>\nYou have superpowers.\n\n**RIGHT NOW, go read**: @${CLAUDE_PLUGIN_ROOT}/skills/getting-started/SKILL.md${github_recommendation}\n</EXTREMELY_IMPORTANT>" } } EOF diff --git a/hooks/setup-personal-superpowers.sh b/hooks/setup-personal-superpowers.sh new file mode 100755 index 0000000..e9e0070 --- /dev/null +++ b/hooks/setup-personal-superpowers.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# Setup script for personal superpowers directory +# Creates personal superpowers directory with git repo for personal skills + +set -euo pipefail + +# Use PERSONAL_SUPERPOWERS_DIR if set, otherwise XDG_CONFIG_HOME/superpowers, otherwise ~/.config/superpowers +SUPERPOWERS_DIR="${PERSONAL_SUPERPOWERS_DIR:-${XDG_CONFIG_HOME:-$HOME/.config}/superpowers}" +SKILLS_DIR="${SUPERPOWERS_DIR}/skills" + +# Check if already set up +if [[ -d "${SUPERPOWERS_DIR}/.git" ]] && [[ -d "${SKILLS_DIR}" ]]; then + # Already set up, nothing to do + exit 0 +fi + +# Create directory structure +mkdir -p "${SKILLS_DIR}" + +# Create .gitignore +cat > "${SUPERPOWERS_DIR}/.gitignore" <<'EOF' +# Superpowers local data +search-log.jsonl +conversation-index/ +conversation-archive/ +EOF + +# Create README +cat > "${SUPERPOWERS_DIR}/README.md" <<'EOF' +# My Personal Superpowers + +Personal skills and techniques for Claude Code. + +Learn more about Superpowers: https://github.com/obra/superpowers +EOF + +# Initialize git repo if not already initialized +if [[ ! -d "${SUPERPOWERS_DIR}/.git" ]]; then + cd "${SUPERPOWERS_DIR}" + git init -q + git add .gitignore README.md + git commit -q -m "Initial commit: Personal superpowers setup" +fi + +# Check for gh and recommend GitHub setup +if command -v gh &> /dev/null; then + echo "github_cli_available=true" +else + echo "github_cli_available=false" +fi + +exit 0 |
