-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·315 lines (252 loc) · 9.71 KB
/
install.sh
File metadata and controls
executable file
·315 lines (252 loc) · 9.71 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/usr/bin/env bash
#
# Dotfiles installer — works on macOS (primary) and Linux (Claude Code sandbox).
# Idempotent: safe to re-run.
#
# Usage:
# git clone https://github.com/zalimeni/dotfiles.git ~/dotfiles
# cd ~/dotfiles && ./install.sh
#
set -euo pipefail
DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"
PLATFORM="$(uname -s)"
info() { printf ' [ \033[00;34m..\033[0m ] %s\n' "$1"; }
ok() { printf ' [ \033[00;32mOK\033[0m ] %s\n' "$1"; }
warn() { printf ' [ \033[0;33m!!\033[0m ] %s\n' "$1"; }
fail() {
printf ' [\033[0;31mFAIL\033[0m] %s\n' "$1"
exit 1
}
# --- helpers ----------------------------------------------------------------
link_file() {
local src="$1" dst="$2"
mkdir -p "$(dirname "$dst")"
if [ -L "$dst" ]; then
rm "$dst"
elif [ -f "$dst" ] || [ -d "$dst" ]; then
mv "$dst" "${dst}.backup"
warn "backed up existing $dst to ${dst}.backup"
fi
ln -sf "$src" "$dst"
ok "linked $dst -> $src"
}
generate_agent_config() {
local generator="$DOTFILES_DIR/bin/sync-agent-config"
[ -x "$generator" ] || fail "missing generator: $generator"
info "regenerating translated agent config"
"$generator"
}
# --- zsh config --------------------------------------------------------
install_zsh() {
info "installing zsh config"
link_file "$DOTFILES_DIR/.config/zsh/.zshrc" "$HOME/.zshrc"
ok "installed zshrc via symlinks"
}
# --- nvim config --------------------------------------------------------
install_nvim() {
info "installing nvim config"
local config_dir="$HOME/.config"
[ ! -e "$config_dir/nvim" ] && ln -s "$DOTFILES_DIR/.config/nvim" "$config_dir"
nvim +PlugInstall +qall
ok "installed nvim config via symlinks"
}
# --- opencode config --------------------------------------------------------
install_opencode() {
info "installing opencode config"
local opencode_dir="$HOME/.config/opencode"
mkdir -p "$opencode_dir"
# AGENTS.md — generated from the canonical Claude instructions.
link_file "$DOTFILES_DIR/.config/opencode/AGENTS.md" "$opencode_dir/AGENTS.md"
# opencode.json — main config (model, MCP servers).
# Does NOT contain auth; opencode stores credentials in ~/.local/share/opencode/.
link_file "$DOTFILES_DIR/.config/opencode/opencode.json" "$opencode_dir/opencode.json"
# package.json — plugin dependencies for ~/.config/opencode/plugins/.
# OpenCode installs these with Bun at startup for local plugins like peon-ping.
if [ -f "$DOTFILES_DIR/.config/opencode/package.json" ]; then
link_file "$DOTFILES_DIR/.config/opencode/package.json" "$opencode_dir/package.json"
fi
# Agents — per-agent symlinks to the generated opencode translations.
# These are generated from .config/claude/agents/ by bin/sync-agent-config.
# Skills are NOT linked here: opencode natively reads ~/.claude/skills/, which
# is already set up by install_claude().
if [ -d "$DOTFILES_DIR/.config/opencode/agents" ]; then
if [ -L "$opencode_dir/agents" ]; then
rm "$opencode_dir/agents"
elif [ -f "$opencode_dir/agents" ]; then
mv "$opencode_dir/agents" "$opencode_dir/agents.backup"
warn "backed up existing $opencode_dir/agents to $opencode_dir/agents.backup"
fi
mkdir -p "$opencode_dir/agents"
for agent_file in "$DOTFILES_DIR/.config/opencode/agents"/*.md; do
link_file "$agent_file" "$opencode_dir/agents/${agent_file##*/}"
done
fi
# Pre-commit hook — keeps opencode agents in sync when Claude agents change.
local hooks_dir="$DOTFILES_DIR/.git/hooks"
if [ -d "$hooks_dir" ]; then
link_file "$DOTFILES_DIR/bin/pre-commit-sync-agents" "$hooks_dir/pre-commit"
ok "installed pre-commit hook (agent sync)"
else
warn "no .git/hooks directory found — skipping pre-commit hook install"
fi
echo ""
info "opencode post-install steps:"
info " 1. cd ~/.config/opencode && npm install (installs plugins)"
info " 2. Run 'opencode /connect', select 'GitHub Copilot', complete auth"
info " 3. Run '/models' inside opencode to confirm model IDs match opencode.json"
info " 4. Set CONTEXT7_KEY env var (or Claude Environments UI) for context7 MCP"
}
# --- Claude Code config -----------------------------------------------------
install_claude() {
info "installing Claude Code config"
local claude_dir="$HOME/.claude"
mkdir -p "$claude_dir"
# Canonical instruction file — exposed under both Claude-compatible and
# tooling-agnostic names so Claude Code and opencode both find it.
link_file "$DOTFILES_DIR/.config/claude/CLAUDE.md" "$claude_dir/CLAUDE.md"
link_file "$DOTFILES_DIR/.config/claude/CLAUDE.md" "$claude_dir/AGENTS.md"
# config.json (MCP servers, LSP)
link_file "$DOTFILES_DIR/.config/claude/config.json" "$claude_dir/config.json"
# Skills — per-skill symlinks
if [ -d "$DOTFILES_DIR/.config/claude/skills" ]; then
mkdir -p "$claude_dir/skills"
for skill_dir in "$DOTFILES_DIR/.config/claude/skills"/*/; do
[ -d "$skill_dir" ] || continue
local skill_name
skill_name="$(basename "$skill_dir")"
link_file "$skill_dir" "$claude_dir/skills/$skill_name"
done
ok "linked skills"
fi
# Agents
if [ -d "$DOTFILES_DIR/.config/claude/agents" ]; then
link_file "$DOTFILES_DIR/.config/claude/agents" "$claude_dir/agents"
fi
# settings.json — platform-dependent
if [ "$PLATFORM" = "Darwin" ]; then
link_file "$DOTFILES_DIR/.config/claude/settings.json" "$claude_dir/settings.json"
else
install_claude_sandbox_settings "$claude_dir/settings.json"
fi
}
install_claude_sandbox_settings() {
local dst="$1"
local src="$DOTFILES_DIR/.config/claude/settings.json"
info "generating sandbox settings.json from $src via jq"
if ! command -v jq &>/dev/null; then
fail "jq is required to generate sandbox settings.json"
fi
# Filter the canonical settings.json:
# - Remove env (secrets/work-specific — set in Claude Environments UI)
# - Remove hooks (peon-ping, macOS audio — no use in sandbox)
# - Remove sandbox block (macOS-specific paths)
# - Remove skipDangerousModePermissionPrompt (local-only preference)
# - Strip permissions.allow entries containing absolute paths (macOS home dir)
jq '
del(.env, .hooks, .sandbox, .skipDangerousModePermissionPrompt)
| .permissions.allow |= map(select(test("/") | not))
' "$src" >"$dst"
ok "wrote $dst (filtered for sandbox — no hooks, no macOS paths)"
}
# --- Git -----------------------------------------------------------
install_git() {
info "configuring git helpers"
# git helpers
if [ -f "$DOTFILES_DIR/git/.githelpers" ]; then
git config --global alias.lg "!source $DOTFILES_DIR/git/.githelpers && pretty_git_log"
git config --global alias.brv "!source $DOTFILES_DIR/git/.githelpers && pretty_git_branch_sorted"
ok "set git aliases (lg, brv)"
fi
}
# --- Shell config -----------------------------------------------------------
install_shell() {
info "installing shell config"
# Add dotfiles/bin to PATH via profile
local profile="$HOME/.profile"
local path_line="export PATH=\"$DOTFILES_DIR/bin:\$PATH\""
if [ -f "$profile" ] && grep -qF "$DOTFILES_DIR/bin" "$profile"; then
ok "PATH already includes dotfiles/bin"
else
echo "" >>"$profile"
echo "# Dotfiles" >>"$profile"
echo "$path_line" >>"$profile"
ok "added dotfiles/bin to PATH in $profile"
fi
# Source portable aliases and functions in shell rc.
# On macOS this is handled by zsh/.zshrc_custom — skip.
if [ "$PLATFORM" != "Darwin" ]; then
local rc="$HOME/.bashrc"
[ -f "$HOME/.zshrc" ] && rc="$HOME/.zshrc"
local source_block="# Dotfiles shell config
for f in \"$DOTFILES_DIR\"/system/.{env.sandbox,alias,function}; do
[ -f \"\$f\" ] && source \"\$f\"
done"
if grep -qF "Dotfiles shell config" "$rc" 2>/dev/null; then
ok "shell config already sourced in $rc"
else
echo "" >>"$rc"
echo "$source_block" >>"$rc"
ok "added shell config to $rc"
fi
fi
}
# --- Sandbox env file -------------------------------------------------------
install_sandbox_env() {
local env_file="$DOTFILES_DIR/system/.env.sandbox"
if [ -f "$env_file" ]; then
ok "sandbox env already exists"
return
fi
info "creating system/.env.sandbox (portable env vars)"
cat >"$env_file" <<'ENV'
# Portable environment variables for Linux/sandbox — sourced by install.sh
# macOS uses system/.env instead (has Homebrew, platform-specific paths)
export EDITOR=vim
export GOPATH="$HOME/go"
export PATH="$GOPATH/bin:$PATH"
export HUSKY=0
export HUSKY_SKIP_HOOKS=1
ENV
ok "wrote $env_file"
}
# --- bat config (optional) --------------------------------------------------
install_bat() {
if ! command -v bat &>/dev/null && ! command -v batcat &>/dev/null; then
warn "bat not found, skipping bat config"
return
fi
link_file "$DOTFILES_DIR/bat" "$HOME/.config/bat"
if command -v bat &>/dev/null; then
bat cache --build 2>/dev/null && ok "rebuilt bat cache" || true
elif command -v batcat &>/dev/null; then
batcat cache --build 2>/dev/null && ok "rebuilt bat cache (batcat)" || true
fi
}
# --- main -------------------------------------------------------------------
main() {
echo ""
echo " dotfiles installer — $([ "$PLATFORM" = "Darwin" ] && echo "macOS" || echo "Linux/sandbox")"
echo ""
generate_agent_config
install_opencode
install_claude
install_git
install_shell
install_zsh
install_nvim
if [ "$PLATFORM" != "Darwin" ]; then
install_sandbox_env
fi
install_bat
echo ""
ok "all done"
if [ "$PLATFORM" != "Darwin" ]; then
echo ""
warn "Sandbox reminder: set these in the Claude Environments UI:"
warn " - CONTEXT7_KEY (for context7 MCP server)"
warn " - Any secrets from system/.private_env"
warn " - SSH key or GitHub token for private repo access"
echo ""
fi
}
main "$@"