-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·107 lines (89 loc) · 3.04 KB
/
install.sh
File metadata and controls
executable file
·107 lines (89 loc) · 3.04 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
103
104
105
106
107
#!/bin/bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CLAUDE_DIR="$HOME/.claude"
BACKUP_DIR="$CLAUDE_DIR/backup-$(date +%Y%m%d-%H%M%S)"
# --- Prompt for user-specific values ---
if [ -z "${PROJECTS_DIR:-}" ]; then
printf "Default projects directory [%s/Projects]: " "$HOME"
read -r PROJECTS_DIR
PROJECTS_DIR="${PROJECTS_DIR:-$HOME/Projects}"
fi
# Expand ~ if present
PROJECTS_DIR="${PROJECTS_DIR/#\~/$HOME}"
# source:destination pairs (symlinked)
SYMLINK_MAPPINGS="
settings.json:$CLAUDE_DIR/settings.json
settings.local.json:$CLAUDE_DIR/settings.local.json
statusline-command.sh:$CLAUDE_DIR/statusline-command.sh
mcp.json:$CLAUDE_DIR/plugins/custom/.mcp.json
"
echo "Installing Claude Code configuration..."
echo "Source: $SCRIPT_DIR"
echo "Target: $CLAUDE_DIR"
echo "Projects dir: $PROJECTS_DIR"
echo ""
mkdir -p "$CLAUDE_DIR"
mkdir -p "$CLAUDE_DIR/plugins/custom"
backed_up=false
backup_if_needed() {
local dest="$1"
local name="$2"
# Skip symlinks and files we previously generated
if [ -e "$dest" ] && [ ! -L "$dest" ] && ! head -1 "$dest" 2>/dev/null | grep -q "^<!-- generated by install.sh -->$"; then
if [ "$backed_up" = false ]; then
mkdir -p "$BACKUP_DIR"
backed_up=true
echo "Backing up existing files to $BACKUP_DIR"
fi
cp "$dest" "$BACKUP_DIR/$name"
echo " Backed up: $name"
fi
}
# Symlink static files
for mapping in $SYMLINK_MAPPINGS; do
src="${mapping%%:*}"
dest="${mapping#*:}"
source_path="$SCRIPT_DIR/$src"
if [ ! -f "$source_path" ]; then
echo "SKIP: $src (not found)"
continue
fi
backup_if_needed "$dest" "$src"
rm -f "$dest"
ln -s "$source_path" "$dest"
echo " Linked: $src -> $dest"
done
# Copy CLAUDE.md with placeholder substitution
if [ -f "$SCRIPT_DIR/CLAUDE.md" ]; then
backup_if_needed "$CLAUDE_DIR/CLAUDE.md" "CLAUDE.md"
rm -f "$CLAUDE_DIR/CLAUDE.md"
{ echo "<!-- generated by install.sh -->"; while IFS= read -r line; do printf '%s\n' "${line//\{\{PROJECTS_DIR\}\}/$PROJECTS_DIR}"; done < "$SCRIPT_DIR/CLAUDE.md"; } > "$CLAUDE_DIR/CLAUDE.md"
echo " Generated: CLAUDE.md (projects dir: $PROJECTS_DIR)"
fi
chmod +x "$SCRIPT_DIR/statusline-command.sh"
# --- Install gstack skills ---
SKILLS_DIR="$CLAUDE_DIR/skills"
GSTACK_DIR="$SKILLS_DIR/gstack"
GSTACK_REPO="https://github.com/garrytan/gstack.git"
mkdir -p "$SKILLS_DIR"
if [ -d "$GSTACK_DIR/.git" ]; then
echo "Updating gstack skills..."
git -C "$GSTACK_DIR" pull --ff-only origin main 2>/dev/null || echo " Warning: gstack update failed (offline or conflict), keeping current version"
else
echo "Installing gstack skills..."
git clone "$GSTACK_REPO" "$GSTACK_DIR"
fi
# Symlink each gstack skill directory that contains a SKILL.md
for skill_dir in "$GSTACK_DIR"/*/; do
skill_name="$(basename "$skill_dir")"
if [ -f "$skill_dir/SKILL.md" ]; then
ln -sfn "gstack/$skill_name" "$SKILLS_DIR/$skill_name"
echo " Linked skill: $skill_name"
fi
done
echo ""
echo "Done. Restart Claude Code to pick up changes."
if [ "$backed_up" = true ]; then
echo "Backups saved to: $BACKUP_DIR"
fi