-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·168 lines (148 loc) · 6.26 KB
/
install.sh
File metadata and controls
executable file
·168 lines (148 loc) · 6.26 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
#!/usr/bin/env bash
# =============================================================================
# install.sh — cloudprobe/dotfiles
# Zero-to-productive setup for a new Mac
#
# Usage:
# ./install.sh # install everything
# ./install.sh zsh # only ZSH + Starship
# ./install.sh git # only Git config
# ./install.sh claude # only Claude Code config
# =============================================================================
set -euo pipefail
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
COMPONENT="${1:-all}"
# ---------- Helpers -----------------------------------------------------------
info() { echo "==> $*"; }
success() { echo "✅ $*"; }
# Symlink helper — creates symlink and strips macOS extended attributes (@)
lns() {
command ln -sf "$1" "$2"
xattr -c "$2" 2>/dev/null || true
}
# ---------- Homebrew ----------------------------------------------------------
ensure_brew() {
if ! command -v brew >/dev/null 2>&1; then
info "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
# ---------- Components --------------------------------------------------------
install_zsh() {
info "Installing ZSH tools..."
ensure_brew
brew install starship zinit eza bat ripgrep zoxide fzf gh pyenv shellcheck shfmt || true
info "Linking ZSH config..."
if [ -f ~/.zshrc ] && [ ! -L ~/.zshrc ]; then
cp ~/.zshrc ~/.zshrc.backup."$(date +%Y%m%d)"
echo " Backed up existing .zshrc"
fi
lns "$DOTFILES_DIR/zsh/.zshrc" ~/.zshrc
lns "$DOTFILES_DIR/zsh/.aliases" ~/.aliases
mkdir -p ~/.config
lns "$DOTFILES_DIR/zsh/starship.toml" ~/.config/starship.toml
info "Pre-loading zinit plugins (so first terminal open is clean)..."
zsh -i -c "zinit load zsh-users/zsh-autosuggestions; zinit load zsh-users/zsh-syntax-highlighting; zinit load zsh-users/zsh-completions; exit" 2>&1 | grep -v "^$" || true
success "ZSH done"
}
install_git() {
info "Linking Git config..."
lns "$DOTFILES_DIR/git/.gitconfig" ~/.gitconfig
lns "$DOTFILES_DIR/git/.gitignore_global" ~/.gitignore_global
lns "$DOTFILES_DIR/git/.yamllint" ~/.yamllint
info "Linking Git hooks..."
lns "$DOTFILES_DIR/git/hooks" ~/.git-hooks
info "Installing hook dependencies..."
ensure_brew
brew install yamllint shellcheck hadolint || true
# SSH commit signing — create allowed_signers from existing key if present
if [ -f ~/.ssh/id_ed25519.pub ]; then
mkdir -p ~/.ssh
email=$(git config user.email 2>/dev/null || true)
if [ -n "$email" ]; then
echo "$email $(cat ~/.ssh/id_ed25519.pub)" > ~/.ssh/allowed_signers
chmod 600 ~/.ssh/allowed_signers
echo " Created ~/.ssh/allowed_signers for local signature verification"
fi
fi
# Repoint dotfiles remote to SSH now that the URL rewrite is active
origin=$(git -C "$DOTFILES_DIR" remote get-url origin 2>/dev/null || true)
if echo "$origin" | grep -q 'https://github.com/'; then
new_origin=$(echo "$origin" | sed 's|https://github.com/|git@github.com:|')
git -C "$DOTFILES_DIR" remote set-url origin "$new_origin"
echo " Switched dotfiles remote: HTTPS → SSH ($new_origin)"
fi
success "Git done"
echo " Remember to create ~/.gitconfig.local with your [user] name and email"
echo " Then add your SSH key as a Signing Key on GitHub:"
echo " https://github.com/settings/keys (choose 'Signing Key', not 'Authentication Key')"
}
install_claude() {
info "Linking Claude Code global config..."
mkdir -p ~/.claude/{commands,rules,skills,agents,memory}
BACKUP_DATE=$(date +%Y%m%d)
# CLAUDE.md — back up existing, then link
# Uses @import so existing content is preserved if user wants to merge manually
if [ -f ~/.claude/CLAUDE.md ] && [ ! -L ~/.claude/CLAUDE.md ]; then
cp ~/.claude/CLAUDE.md ~/.claude/CLAUDE.md.backup."$BACKUP_DATE"
echo " Backed up existing CLAUDE.md to ~/.claude/CLAUDE.md.backup.$BACKUP_DATE"
fi
lns "$DOTFILES_DIR/claude/CLAUDE.md" ~/.claude/CLAUDE.md
# settings.json — only link on fresh installs; skip if a real file exists
# (existing installs accumulate machine-specific config: plugins, model, permissions)
if [ -f ~/.claude/settings.json ] && [ ! -L ~/.claude/settings.json ]; then
echo " Skipped settings.json — real file exists with custom config (plugins, model, etc.)"
echo " To apply hooks from this dotfiles: manually merge ~/.claude/settings.json"
echo " with $DOTFILES_DIR/claude/settings.json (hooks block)"
else
lns "$DOTFILES_DIR/claude/settings.json" ~/.claude/settings.json
fi
# commands/rules/skills/agents — skip files that already exist (don't overwrite custom ones)
# Handles both flat *.md files and subdirectory-based skills (e.g. skills/research/SKILL.md)
for dir in commands rules skills agents; do
for f in "$DOTFILES_DIR/claude/$dir/"*.md "$DOTFILES_DIR/claude/$dir/"*/; do
[ -e "$f" ] || continue
name=$(basename "${f%/}")
dest=~/.claude/$dir/$name
if [ -e "$dest" ] && [ ! -L "$dest" ]; then
echo " Skipped $dir/$name — already exists (not overwriting)"
else
lns "${f%/}" "$dest"
fi
done
done
lns "$DOTFILES_DIR/claude/memory/README.md" ~/.claude/memory/README.md
success "Claude Code done"
}
# ---------- Main --------------------------------------------------------------
case "$COMPONENT" in
zsh) install_zsh ;;
git) install_git ;;
claude) install_claude ;;
all)
install_zsh
install_git
install_claude
echo ""
success "All done. Open a new terminal session to apply changes."
echo ""
echo "Next steps:"
echo " 1. Create ~/.gitconfig.local:"
echo " [user]"
echo " name = Your Name"
echo " email = your@email.com"
echo ""
echo " 2. Create ~/.zshrc.local for machine-specific env vars:"
echo " cp $DOTFILES_DIR/zsh/.zshrc.local.template ~/.zshrc.local"
echo ""
echo " 3. Set up AWS profiles:"
echo " mkdir -p ~/.aws && cp $DOTFILES_DIR/aws/config.sample ~/.aws/config"
echo ""
echo " 4. For new projects: copy claude/project-template/ into your repo as .claude/"
;;
*)
echo "Unknown component: $COMPONENT"
echo "Usage: ./install.sh [all|zsh|git|claude]"
exit 1
;;
esac