-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·98 lines (85 loc) · 2.92 KB
/
install.sh
File metadata and controls
executable file
·98 lines (85 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
set -euo pipefail
# install.sh — Install code-diary hook for Claude Code
# Creates a "Code" Reminders list and registers a global PostToolUse hook
# that logs git commits and PRs as completed Reminders.
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
HOOK_SRC="${SCRIPT_DIR}/code-diary.sh"
HOOK_DIR="${HOME}/.claude/hooks"
HOOK_DEST="${HOOK_DIR}/code-diary.sh"
SETTINGS="${HOME}/.claude/settings.json"
echo "=== Code Diary Hook Installer ==="
echo ""
# --- Check dependencies ---
MISSING=()
if ! command -v reminders &>/dev/null; then
MISSING+=("reminders-cli (brew install keith/formulae/reminders-cli)")
fi
if ! command -v jq &>/dev/null; then
MISSING+=("jq (brew install jq)")
fi
if ! command -v git &>/dev/null; then
MISSING+=("git")
fi
if [ ${#MISSING[@]} -gt 0 ]; then
echo "Missing dependencies:"
for dep in "${MISSING[@]}"; do
echo " - $dep"
done
echo ""
read -p "Install missing dependencies via Homebrew? [y/N] " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
command -v reminders &>/dev/null || brew install keith/formulae/reminders-cli
command -v jq &>/dev/null || brew install jq
else
echo "Please install dependencies and re-run."
exit 1
fi
fi
echo "[ok] Dependencies: reminders-cli, jq, git"
# --- Copy hook script ---
mkdir -p "$HOOK_DIR"
cp "$HOOK_SRC" "$HOOK_DEST"
chmod +x "$HOOK_DEST"
echo "[ok] Hook script installed to ${HOOK_DEST}"
# --- Ensure "Code" list exists in Reminders ---
reminders new-list "Code" 2>/dev/null || true
echo "[ok] Reminders 'Code' list ready"
# --- Register hook in settings.json ---
if [ ! -f "$SETTINGS" ]; then
# Create minimal settings.json
echo '{}' > "$SETTINGS"
fi
# Check if code-diary hook is already registered
if jq -e '.hooks.PostToolUse[]? | select(.hooks[]?.command | test("code-diary"))' "$SETTINGS" &>/dev/null; then
echo "[ok] Hook already registered in settings.json (skipped)"
else
# Add the hook entry using jq
HOOK_ENTRY='{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "'"${HOOK_DEST}"'",
"timeout": 5
}
]
}'
# Ensure hooks.PostToolUse array exists, then append
UPDATED=$(jq --argjson entry "$HOOK_ENTRY" '
.hooks //= {} |
.hooks.PostToolUse //= [] |
.hooks.PostToolUse += [$entry]
' "$SETTINGS")
echo "$UPDATED" > "$SETTINGS"
echo "[ok] Hook registered in ${SETTINGS}"
fi
echo ""
echo "=== Installation complete ==="
echo ""
echo "The hook will create a completed Reminder in the 'Code' list"
echo "whenever Claude Code runs: git commit, gh pr create, or gh pr merge."
echo ""
echo "To uninstall: ./uninstall.sh"
echo "To test: echo '{\"tool_name\":\"Bash\",\"tool_input\":{\"command\":\"git commit -m test\"},\"tool_response\":\"[main abc1234] test message\\n 1 file changed\",\"cwd\":\"/tmp/test\"}' | ${HOOK_DEST}"