-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·454 lines (397 loc) · 16.2 KB
/
setup.sh
File metadata and controls
executable file
·454 lines (397 loc) · 16.2 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#!/usr/bin/env bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
print_header() {
echo -e "\n${BLUE}===================================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}===================================================${NC}\n"
}
print_success() { echo -e "${GREEN}✓ $1${NC}"; }
print_warning() { echo -e "${YELLOW}⚠ $1${NC}"; }
print_error() { echo -e "${RED}✗ $1${NC}"; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
print_header "majorgreys dev setup for macos"
# Check macOS
if [[ "$OSTYPE" != "darwin"* ]]; then
print_error "This script is designed for macOS only."
exit 1
fi
# ===================================
# Install Homebrew
# ===================================
print_header "Checking Homebrew"
if command_exists brew; then
print_success "Homebrew already installed: $(brew --version | head -n1)"
else
print_warning "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Add to PATH for Apple Silicon
if [[ $(uname -m) == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
print_success "Homebrew installed"
fi
# ===================================
# Install Brewfile packages
# ===================================
print_header "Installing Brewfile packages"
# Detect dotfiles directory (script location)
DOTFILES_DIR="$(cd "$(dirname "$0")" && pwd)"
if [[ -f "$DOTFILES_DIR/Brewfile" ]]; then
# Ensure libgccjit is working before brew bundle (required by emacs-plus native compilation)
if brew list libgccjit &>/dev/null && ! brew test libgccjit &>/dev/null 2>&1; then
print_warning "Reinstalling libgccjit (test failed)..."
brew reinstall libgccjit
fi
print_warning "Running 'brew bundle install'..."
cd "$DOTFILES_DIR" && brew bundle install
print_success "Brewfile packages installed"
else
print_error "Brewfile not found at $DOTFILES_DIR/Brewfile"
exit 1
fi
# Fix jpeg dylib mismatch: emacs-plus may be linked against libjpeg.9.dylib
# but jpeg was upgraded to v10. Create a compatibility symlink.
JPEG_LIB_DIR="/opt/homebrew/opt/jpeg/lib"
if [[ -d "$JPEG_LIB_DIR" && ! -f "$JPEG_LIB_DIR/libjpeg.9.dylib" ]]; then
CURRENT_JPEG=$(ls "$JPEG_LIB_DIR"/libjpeg.*.dylib 2>/dev/null | head -1)
if [[ -n "$CURRENT_JPEG" ]]; then
print_warning "Creating jpeg compatibility symlink (libjpeg.9.dylib -> $(basename "$CURRENT_JPEG"))..."
ln -sf "$CURRENT_JPEG" "$JPEG_LIB_DIR/libjpeg.9.dylib"
print_success "jpeg compatibility symlink created"
fi
fi
# Link Emacs to Applications
if [[ -d "/opt/homebrew/opt/emacs-plus@30/Emacs.app" ]]; then
ln -sf /opt/homebrew/opt/emacs-plus@30/Emacs.app /Applications/Emacs.app
elif [[ -d "/usr/local/opt/emacs-plus@30/Emacs.app" ]]; then
ln -sf /usr/local/opt/emacs-plus@30/Emacs.app /Applications/Emacs.app
fi
# Setup Emacs LaunchAgent
EMACS_PLIST="$HOME/Library/LaunchAgents/homebrew.mxcl.emacs-plus@30.plist"
EMACS_BIN="/opt/homebrew/bin/emacs"
mkdir -p "$HOME/Library/LaunchAgents"
if [[ ! -f "$EMACS_PLIST" ]] || ! /usr/libexec/PlistBuddy -c "Print :ProgramArguments" "$EMACS_PLIST" &>/dev/null; then
print_warning "Creating Emacs LaunchAgent..."
# Create plist with required keys
/usr/libexec/PlistBuddy -c "Add :Label string org.gnu.emacs.daemon" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :ProgramArguments array" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :ProgramArguments:0 string $EMACS_BIN" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :ProgramArguments:1 string --daemon" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :RunAtLoad bool true" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :StandardErrorPath string /tmp/emacs-daemon.err" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :StandardOutPath string /tmp/emacs-daemon.log" "$EMACS_PLIST" 2>/dev/null || true
print_success "Emacs LaunchAgent created"
fi
# Add Ghostty TERMINFO if Ghostty is installed
if [[ -d "/Applications/Ghostty.app" ]]; then
print_warning "Configuring Ghostty TERMINFO..."
/usr/libexec/PlistBuddy -c "Add :EnvironmentVariables dict" "$EMACS_PLIST" 2>/dev/null || true
/usr/libexec/PlistBuddy -c "Add :EnvironmentVariables:TERMINFO string /Applications/Ghostty.app/Contents/Resources/terminfo" "$EMACS_PLIST" 2>/dev/null || \
/usr/libexec/PlistBuddy -c "Set :EnvironmentVariables:TERMINFO /Applications/Ghostty.app/Contents/Resources/terminfo" "$EMACS_PLIST"
print_success "Ghostty TERMINFO configured"
fi
# ===================================
# Install Rust
# ===================================
print_header "Installing Rust"
if command_exists rustc; then
print_success "Rust already installed: $(rustc --version)"
else
print_warning "Installing Rust via rustup..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"
print_success "Rust installed"
fi
if command_exists rust-analyzer; then
print_success "rust-analyzer already installed"
else
print_warning "Installing rust-analyzer..."
rustup component add rust-analyzer
print_success "rust-analyzer installed"
fi
# ===================================
# Install Python tools via uv
# ===================================
print_header "Installing Python tools"
print_warning "Installing Python tools via uv..."
uv tool install pyright
uv tool install ruff
uv tool install black
uv tool install pyflakes
uv tool install isort
uv tool install pipenv
uv tool install pytest
uv tool install nose
print_success "Python tools installed"
# ===================================
# Install Go tools
# ===================================
print_header "Installing Go tools"
# Install gopls
if command_exists gopls; then
print_success "gopls already installed"
else
print_warning "Installing gopls..."
go install golang.org/x/tools/gopls@latest
print_success "gopls installed"
fi
# Install additional Go tools for Doom Emacs
print_warning "Installing Go development tools..."
go install github.com/fatih/gomodifytags@latest
go install github.com/cweill/gotests/gotests@latest
go install github.com/x-motemen/gore/cmd/gore@latest
print_success "Go development tools installed"
# ===================================
# Install Beads (git-backed issue tracker)
# ===================================
print_header "Installing Beads"
if command_exists bd; then
print_success "Beads already installed: $(bd version 2>/dev/null || echo 'installed')"
else
print_warning "Installing Beads..."
curl -fsSL https://raw.githubusercontent.com/steveyegge/beads/main/scripts/install.sh | bash
print_success "Beads installed"
fi
# ===================================
# Setup dotfiles with stow
# ===================================
print_header "Setting up dotfiles with stow"
# Stow configs for installed tools
configs=("fish" "ghostty" "tmux" "vim" "helix" "doom" "thbemacs" "starship" "aerospace" "org-autosync")
for config in "${configs[@]}"; do
if [[ -d "$DOTFILES_DIR/$config" ]]; then
print_warning "Stowing $config config..."
if (cd "$DOTFILES_DIR" && stow "$config" 2>/dev/null); then
print_success "$config config stowed"
else
print_warning "stow $config failed (may already be stowed)"
fi
fi
done
# Setup fisher and fish plugins
if command_exists fish; then
print_warning "Setting up fisher and fish plugins..."
# Install fisher if not present
if ! fish -c 'type -q fisher' 2>/dev/null; then
print_warning "Installing fisher..."
fish -c 'curl -sL https://raw.githubusercontent.com/jorgebucaran/fisher/main/functions/fisher.fish | source && fisher install jorgebucaran/fisher'
print_success "Fisher installed"
else
print_success "Fisher already installed"
fi
# Install plugins from fish_plugins file
if [[ -f "$HOME/.config/fish/fish_plugins" ]]; then
print_warning "Installing fish plugins..."
fish -c 'fisher update'
print_success "Fish plugins installed"
fi
fi
# ===================================
# Setup Doom Emacs
# ===================================
print_header "Setting up Doom Emacs"
DOOM_DIR="$HOME/.config/emacs"
DOOM_BIN="$DOOM_DIR/bin/doom"
if [[ -d "$DOOM_DIR" ]]; then
print_success "Doom Emacs already cloned"
else
print_warning "Cloning Doom Emacs..."
git clone --depth 1 https://github.com/doomemacs/doomemacs "$DOOM_DIR"
print_success "Doom Emacs cloned"
fi
# Add doom to PATH for current session
export PATH="$HOME/.config/emacs/bin:$PATH"
# Install/sync Doom
if [[ -f "$HOME/.config/emacs/.local/straight/repos/straight.el/README.md" ]]; then
print_success "Doom already installed"
print_warning "Running 'doom sync'..."
"$DOOM_BIN" sync --yes
else
print_warning "Running 'doom install'..."
"$DOOM_BIN" install
print_success "Doom installed"
fi
# ===================================
# Load/Restart Emacs LaunchAgents
# ===================================
print_header "Loading Emacs LaunchAgents"
# Generate org-autosync LaunchAgent from template
AUTOSYNC_PLIST="$HOME/Library/LaunchAgents/com.thb.org-autosync.plist"
AUTOSYNC_TEMPLATE="$DOTFILES_DIR/templates/com.thb.org-autosync.plist.template"
if [[ -f "$AUTOSYNC_TEMPLATE" ]]; then
print_warning "Generating org-autosync LaunchAgent..."
mkdir -p "$HOME/Library/LaunchAgents"
mkdir -p "$HOME/.local/share/org-autosync"
sed "s|__HOME__|$HOME|g" "$AUTOSYNC_TEMPLATE" > "$AUTOSYNC_PLIST"
print_success "org-autosync LaunchAgent generated"
if launchctl list com.thb.org-autosync &>/dev/null; then
print_warning "Reloading org-autosync..."
launchctl unload "$AUTOSYNC_PLIST"
launchctl load "$AUTOSYNC_PLIST"
print_success "org-autosync reloaded"
else
print_warning "Starting org-autosync..."
launchctl load "$AUTOSYNC_PLIST"
print_success "org-autosync started"
fi
fi
# Generate thbemacs LaunchAgent from template
THBEMACS_PLIST="$HOME/Library/LaunchAgents/com.thbemacs.daemon.plist"
THBEMACS_TEMPLATE="$DOTFILES_DIR/templates/com.thbemacs.daemon.plist.template"
if [[ -f "$THBEMACS_TEMPLATE" ]]; then
print_warning "Generating thbemacs LaunchAgent..."
mkdir -p "$HOME/Library/LaunchAgents"
sed "s|__HOME__|$HOME|g" "$THBEMACS_TEMPLATE" > "$THBEMACS_PLIST"
print_success "thbemacs LaunchAgent generated"
if launchctl list com.thbemacs.daemon &>/dev/null; then
print_warning "Reloading thbemacs daemon..."
launchctl unload "$THBEMACS_PLIST"
launchctl load "$THBEMACS_PLIST"
print_success "thbemacs daemon reloaded"
else
print_warning "Starting thbemacs daemon..."
launchctl load "$THBEMACS_PLIST"
print_success "thbemacs daemon started"
fi
fi
# Generate Doom Emacs LaunchAgent from template
DOOM_PLIST="$HOME/Library/LaunchAgents/com.thb.doom-emacs.plist"
DOOM_TEMPLATE="$DOTFILES_DIR/templates/com.thb.doom-emacs.plist.template"
if [[ -f "$DOOM_TEMPLATE" ]]; then
print_warning "Generating Doom Emacs LaunchAgent..."
mkdir -p "$HOME/Library/LaunchAgents"
mkdir -p "$HOME/.local/share/doom-emacs"
sed "s|__HOME__|$HOME|g" "$DOOM_TEMPLATE" > "$DOOM_PLIST"
print_success "Doom Emacs LaunchAgent generated"
# Unload old homebrew plist if it exists
OLD_EMACS_PLIST="$HOME/Library/LaunchAgents/homebrew.mxcl.emacs-plus@30.plist"
if launchctl list org.gnu.emacs.daemon &>/dev/null; then
print_warning "Unloading old Emacs daemon..."
launchctl unload "$OLD_EMACS_PLIST" 2>/dev/null || true
fi
if launchctl list com.thb.doom-emacs &>/dev/null; then
print_warning "Reloading Doom Emacs daemon..."
launchctl unload "$DOOM_PLIST"
launchctl load "$DOOM_PLIST"
print_success "Doom Emacs daemon reloaded"
else
print_warning "Starting Doom Emacs daemon..."
launchctl load "$DOOM_PLIST"
print_success "Doom Emacs daemon started"
fi
fi
# ===================================
# Run doom doctor
# ===================================
print_header "Running Doom Doctor"
if [[ -x "$DOOM_BIN" ]]; then
print_warning "Checking Doom configuration..."
if "$DOOM_BIN" doctor; then
print_success "doom doctor completed!"
else
print_warning "doom doctor found issues - please review above"
fi
fi
# ===================================
# Configure Docker Compose Plugin
# ===================================
print_header "Configuring Docker Compose Plugin"
# Create Docker CLI plugins directory
if [[ ! -d "$HOME/.docker/cli-plugins" ]]; then
print_warning "Creating Docker CLI plugins directory..."
mkdir -p "$HOME/.docker/cli-plugins"
print_success "Created ~/.docker/cli-plugins"
fi
# Symlink docker-compose as a Docker plugin
DOCKER_COMPOSE_BIN="$(brew --prefix)/opt/docker-compose/bin/docker-compose"
DOCKER_COMPOSE_PLUGIN="$HOME/.docker/cli-plugins/docker-compose"
if [[ -f "$DOCKER_COMPOSE_BIN" ]]; then
if [[ -L "$DOCKER_COMPOSE_PLUGIN" ]]; then
print_success "Docker Compose plugin already configured"
else
print_warning "Symlinking docker-compose as Docker plugin..."
ln -sfn "$DOCKER_COMPOSE_BIN" "$DOCKER_COMPOSE_PLUGIN"
print_success "Docker Compose plugin configured"
fi
else
print_warning "docker-compose binary not found at $DOCKER_COMPOSE_BIN"
fi
# ===================================
# Start Colima
# ===================================
print_header "Starting Colima"
if colima status &>/dev/null; then
print_success "Colima already running"
else
print_warning "Starting Colima..."
colima start
print_success "Colima started"
fi
# ===================================
# Test Colima & Docker
# ===================================
print_header "Testing Colima & Docker"
if [[ -x "$DOTFILES_DIR/test-docker.sh" ]]; then
"$DOTFILES_DIR/test-docker.sh"
else
print_warning "test-docker.sh not found, running basic tests..."
# Test Colima status
print_warning "Checking Colima status..."
if colima status &>/dev/null; then
COLIMA_STATUS=$(colima status 2>&1 | head -n1)
print_success "Colima is running: $COLIMA_STATUS"
else
print_error "Colima is not running"
fi
# Test Docker daemon
print_warning "Testing Docker daemon..."
if docker info &>/dev/null; then
DOCKER_VERSION=$(docker version --format '{{.Server.Version}}' 2>/dev/null)
print_success "Docker daemon is accessible (version: $DOCKER_VERSION)"
else
print_error "Docker daemon is not accessible"
fi
# Test Docker with a simple command
print_warning "Testing Docker functionality..."
if docker ps &>/dev/null; then
CONTAINER_COUNT=$(docker ps -q | wc -l | tr -d ' ')
print_success "Docker is working (running containers: $CONTAINER_COUNT)"
else
print_error "Docker ps command failed"
fi
fi
# ===================================
# Summary
# ===================================
print_header "Setup Complete!"
echo -e "${GREEN}Your development environment is ready!${NC}\n"
echo "Installed components:"
echo " ✓ Editors: Emacs, Doom, Neovim, Helix"
echo " ✓ Python $(python3 --version 2>/dev/null | cut -d' ' -f2 || echo 'installed') + uv, pyright, ruff, black"
echo " ✓ Go $(go version 2>/dev/null | cut -d' ' -f3 || echo 'installed') + gopls"
echo " ✓ Rust $(rustc --version 2>/dev/null | cut -d' ' -f2 || echo 'installed') + rust-analyzer"
echo " ✓ Zig $(zig version 2>/dev/null || echo 'installed')"
echo " ✓ Shells: Fish, tmux"
echo " ✓ Colima & Docker (tested and working)"
echo " ✓ CLI tools: bat, eza, htop, jq, yq, zoxide, ripgrep, fd, fzf"
echo " ✓ Dev tools: git, gh, git-delta, stow, direnv"
echo " ✓ Programming fonts"
echo -e "\n${YELLOW}Next steps:${NC}"
echo " 1. Restart your shell:"
echo " ${BLUE}exec \$SHELL${NC}"
echo ""
echo " 2. Your Doom config is at: ${BLUE}$HOME/.config/doom${NC}"
echo ""
echo " 3. Review 'doom doctor' output above"
echo ""
echo " 4. After modifying config, run: ${BLUE}doom sync${NC}"
echo ""
echo " 5. Colima commands:"
echo " ${BLUE}colima status${NC} / ${BLUE}colima stop${NC} / ${BLUE}colima start${NC}"
print_success "Happy coding!"