-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·102 lines (92 loc) · 2.97 KB
/
install.sh
File metadata and controls
executable file
·102 lines (92 loc) · 2.97 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
99
100
101
102
#!/usr/bin/env bash
#
# cc-diff installer
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="${HOME}/.local/bin"
CLAUDE_SETTINGS="${HOME}/.claude/settings.json"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo "Installing cc-diff..."
# 1. Ensure install directory exists and is in PATH
mkdir -p "$INSTALL_DIR"
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo -e "${YELLOW}Note:${NC} $INSTALL_DIR is not in your PATH"
echo "Add this to your ~/.zshrc:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
# 2. Symlink the script
if [[ -L "$INSTALL_DIR/cc-diff" ]]; then
rm "$INSTALL_DIR/cc-diff"
fi
ln -sf "$SCRIPT_DIR/cc-diff" "$INSTALL_DIR/cc-diff"
echo -e "${GREEN}✓${NC} Linked cc-diff to $INSTALL_DIR/cc-diff"
# 3. Update Claude Code settings with hook
if [[ -f "$CLAUDE_SETTINGS" ]]; then
# Check if hooks already exist
if grep -q '"hooks"' "$CLAUDE_SETTINGS" 2>/dev/null; then
echo -e "${YELLOW}!${NC} hooks already exist in $CLAUDE_SETTINGS"
echo " Please manually add the PostToolUse hook. See README.md"
else
# Use jq if available, otherwise use a simple approach
if command -v jq &>/dev/null; then
tmp=$(mktemp)
jq '. + {
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "cc-diff log"
}
]
}
]
}
}' "$CLAUDE_SETTINGS" > "$tmp" && mv "$tmp" "$CLAUDE_SETTINGS"
echo -e "${GREEN}✓${NC} Added PostToolUse hook to Claude Code settings"
else
echo -e "${YELLOW}!${NC} jq not found. Please manually add hooks to $CLAUDE_SETTINGS"
echo " See README.md for the configuration."
fi
fi
else
# Create settings file
mkdir -p "$(dirname "$CLAUDE_SETTINGS")"
cat > "$CLAUDE_SETTINGS" <<EOF
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "cc-diff log"
}
]
}
]
}
}
EOF
echo -e "${GREEN}✓${NC} Created Claude Code settings with hook"
fi
# 4. Check for fzf
if ! command -v fzf &>/dev/null; then
echo -e "${YELLOW}!${NC} fzf not installed. Install with: brew install fzf"
fi
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo "Usage:"
echo " cc-diff Browse changed files interactively"
echo " cc-diff list List changed files"
echo " cc-diff clear Clear the log (before starting a new task)"
echo ""
echo "From within Claude Code, use: !cc-diff"