-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.sh
More file actions
641 lines (552 loc) · 22.7 KB
/
Copy pathsetup.sh
File metadata and controls
641 lines (552 loc) · 22.7 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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
#!/bin/bash
# Dotfiles Automated Setup Script
# Universal configuration for all environments
#
# USAGE: source setup.sh
# Don't exit on error - this is critical for Pop!_OS compatibility
set +e
# Define colors and formatting
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
DIVIDER="----------------------------------------"
# Error handling function
handle_error() {
local exit_code=$?
echo -e "${RED}Command failed with exit code $exit_code: $BASH_COMMAND${NC}"
echo -e "${YELLOW}Continuing despite error...${NC}"
}
# Set up error trap but don't exit
trap 'handle_error' ERR
# Check if the script is being sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
echo -e "${RED}Error: This script must be sourced, not executed.${NC}"
echo -e "Please run: ${GREEN}source setup.sh${NC}"
exit 1
fi
# Add debug logging
echo "Debug: Starting setup script in sourced mode"
# Determine dotfiles root relative to this script's location
# Works from main repo OR worktrees - everything is relative to where you source from
# This makes the system self-documenting: source from where you want to work
DOT_DEN="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Export DOT_DEN as a global variable for other scripts to use
export DOT_DEN
# Critical: Warn if running from worktree to prevent broken symlinks
if [[ "$DOT_DEN" == *"/worktrees/"* ]]; then
echo -e "${YELLOW}WARNING: Running setup.sh from a worktree directory!${NC}"
echo -e "${YELLOW}This will create symlinks that break when the worktree is deleted.${NC}"
echo -e "${YELLOW}Consider running from the main repository instead.${NC}"
# Remove user interaction and continue with the script
echo -e "${YELLOW}Proceeding with setup - broken symlinks will be handled automatically.${NC}"
fi
# Add MCP directory to PATH for easier access to MCP scripts
export PATH="$DOT_DEN/mcp:$PATH"
# Add MCP servers directory to PATH
export PATH="$DOT_DEN/mcp/servers:$PATH"
# Export flag to tell subscripts we're running from the main setup
export SETUP_SCRIPT_RUNNING=true
# Disable Claude Code Bedrock usage by default
export CLAUDE_CODE_USE_BEDROCK=0
echo -e "${DIVIDER}"
echo -e "${GREEN}Setting up dotfiles...${NC}"
echo -e "${DIVIDER}"
# Check for essential tools
check_command() {
if ! command -v "$1" &> /dev/null; then
echo -e "${RED}Required command '$1' not found.${NC}"
echo "Please install it using your package manager before running this script."
echo "See the README.md for OS-specific installation instructions."
return 1
fi
return 0
}
# Check for essential commands
essential_commands=("git" "curl")
missing_commands=false
for cmd in "${essential_commands[@]}"; do
if ! check_command "$cmd"; then
missing_commands=true
fi
done
if [[ "$missing_commands" == true ]]; then
echo -e "${RED}Please install the missing commands and run this script again.${NC}"
return 1
fi
# Determine OS type
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS_TYPE="Linux"
if grep -q Microsoft /proc/version 2>/dev/null; then
echo "Detected Windows Subsystem for Linux (WSL)"
IS_WSL=true
else
IS_WSL=false
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
OS_TYPE="macOS"
IS_WSL=false
else
echo "Unrecognized OS: $OSTYPE. Proceeding anyway..."
OS_TYPE="Unknown"
IS_WSL=false
fi
echo "Detected OS: $OS_TYPE"
# Ensure jq is present on apt-based Linux/WSL
# Ensure jq is present on apt-based Linux/WSL
if [[ "$OS_TYPE" == "Linux" ]] && ! command -v jq >/dev/null && command -v apt-get >/dev/null; then
echo "Installing jq..."
sudo apt-get update -y && sudo apt-get install -y jq
fi
# Handle WSL-specific setup
if [[ "$IS_WSL" == true ]]; then
echo "Setting up WSL-specific configuration..."
if [[ -d "/mnt/c/dotfiles" ]]; then
echo "Found dotfiles in Windows filesystem, creating symlink..."
ln -sf /mnt/c/dotfiles "$DOT_DEN"
fi
fi
# Clone dotfiles repository if it doesn't exist and we're not in WSL
if [[ ! -d "$DOT_DEN" && "$IS_WSL" == false ]]; then
echo "Cloning dotfiles repository..."
mkdir -p "$(dirname "$DOT_DEN")"
git clone https://github.com/atxtechbro/dotfiles.git "$DOT_DEN" 2>/dev/null
echo -e "${GREEN}✓ Repository cloned successfully${NC}"
elif [[ -d "$DOT_DEN" ]]; then
echo "Dotfiles repository already exists at $DOT_DEN"
# Removed cd command to prevent changing user's directory when sourced
fi
# Neovim configuration setup
if [[ -f "$DOT_DEN/utils/install-neovim.sh" ]]; then
source "$DOT_DEN/utils/install-neovim.sh"
setup_neovim || {
echo -e "${YELLOW}Neovim setup encountered issues but continuing...${NC}"
}
else
echo -e "${YELLOW}Neovim installation script not found. Skipping Neovim setup.${NC}"
echo -e "${BLUE}To use Neovim configuration manually:${NC}"
echo -e "${BLUE}1. Install Neovim${NC}"
echo -e "${BLUE}2. Run: ln -sfn $DOT_DEN/nvim ~/.config/nvim${NC}"
fi
# Create symlinks for other configuration files
echo "Creating symlinks for config files..."
# Critical: Detect and fix broken symlinks from deleted worktrees
echo "Checking for broken symlinks from deleted worktrees..."
for config_file in .bashrc .bash_aliases .bash_profile .bash_exports .tmux.conf .zprofile .zshrc .zsh_prompt; do
home_link="$HOME/$config_file"
if [[ -L "$home_link" && ! -e "$home_link" ]]; then
echo "Removing broken symlink: $home_link"
rm -f "$home_link"
fi
done
ln -sf "$DOT_DEN/.bashrc" ~/.bashrc
ln -sf "$DOT_DEN/.bash_aliases" ~/.bash_aliases
ln -sf "$DOT_DEN/.bash_profile" ~/.bash_profile
# Create directory for modular aliases if it doesn't exist
mkdir -p ~/.bash_aliases.d
# Copy the contents instead of creating a symlink to avoid recursive symlink issues
cp -r "$DOT_DEN/.bash_aliases.d/"* ~/.bash_aliases.d/ 2>/dev/null || true
ln -sf "$DOT_DEN/.bash_exports" ~/.bash_exports
ln -sf "$DOT_DEN/.tmux.conf" ~/.tmux.conf
# macOS-specific shell configuration
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "Setting up macOS shell configuration..."
ln -sf "$DOT_DEN/.zprofile" ~/.zprofile
# Ensure Homebrew is installed
source "$DOT_DEN/utils/ensure-homebrew.sh"
ensure_homebrew_on_macos
# Install coreutils for timeout command
if ! command -v timeout &> /dev/null && ! command -v gtimeout &> /dev/null; then
echo "Installing coreutils for timeout command..."
brew install coreutils
echo -e "${GREEN}✓ coreutils installed (timeout available as gtimeout)${NC}"
fi
# Configure iTerm2 as default terminal
echo "Configuring iTerm2 as default terminal..."
defaults write com.apple.LaunchServices/com.apple.launchservices.secure LSHandlers -array-add '{LSHandlerContentType="public.unix-executable";LSHandlerRoleAll="com.googlecode.iterm2";}'
echo -e "${GREEN}✓ iTerm2 configured as default terminal${NC}"
ln -sf "$DOT_DEN/.zshrc" ~/.zshrc
ln -sf "$DOT_DEN/.zsh_prompt" ~/.zsh_prompt
echo -e "${GREEN}✓ zprofile, zshrc, and zsh_prompt linked for macOS shell setup${NC}"
# Offer iTerm2 installation for better terminal experience
echo -e "${DIVIDER}"
echo "Terminal setup for macOS..."
if [[ -f "$DOT_DEN/utils/install-iterm2.sh" ]]; then
source "$DOT_DEN/utils/install-iterm2.sh"
install_iterm2
if [[ -f "$DOT_DEN/utils/configure-iterm2.sh" ]]; then
source "$DOT_DEN/utils/configure-iterm2.sh"
configure_iterm2
fi
fi
fi
# Set up Git configuration
echo "Setting up Git configuration..."
gitconfig_path="$HOME/.gitconfig"
dotfiles_gitconfig="$DOT_DEN/.gitconfig"
# Remove existing gitconfig and copy fresh
rm -f "$gitconfig_path"
cp "$dotfiles_gitconfig" "$gitconfig_path"
echo -e "${GREEN}✓ Git configuration created${NC}"
# Set up modular Git configurations
echo "Setting up modular Git configurations..."
# Work Git configuration
work_gitconfig_source="$DOT_DEN/.gitconfig.work"
work_gitconfig_target="$HOME/.gitconfig-work"
if [[ -f "$work_gitconfig_source" ]]; then
ln -sf "$work_gitconfig_source" "$work_gitconfig_target"
echo -e "${GREEN}✓ Work Git configuration linked${NC}"
fi
# Create machine-specific exports file from template
if [[ -f "$DOT_DEN/.bash_exports.local.example" && ! -f ~/.bash_exports.local ]]; then
echo "Creating machine-specific exports file from template..."
cp "$DOT_DEN/.bash_exports.local.example" ~/.bash_exports.local
echo "Created ~/.bash_exports.local from template. Please edit to configure your environment."
fi
# Create secrets file from template
if [[ -f "$DOT_DEN/.bash_secrets.example" && ! -f ~/.bash_secrets ]]; then
echo "Creating secrets file from template..."
cp "$DOT_DEN/.bash_secrets.example" ~/.bash_secrets
chmod 600 ~/.bash_secrets
echo "Created ~/.bash_secrets from template. Please edit to add your secrets."
fi
# Source bash exports early to make environment variables available for MCP configuration
echo "Loading environment variables from bash_exports..."
if [[ -f ~/.bash_exports ]]; then
# shellcheck disable=SC1090
source ~/.bash_exports
echo -e "${GREEN}✓ Environment variables loaded successfully${NC}"
fi
# Configure Amazon Q knowledge integration
if [[ -f "$DOT_DEN/utils/configure-amazonq.sh" ]]; then
"$DOT_DEN/utils/configure-amazonq.sh"
fi
# Set up vendor-agnostic MCP configuration
if [[ -f "$DOT_DEN/mcp/setup-vendor-agnostic-mcp.sh" ]]; then
"$DOT_DEN/mcp/setup-vendor-agnostic-mcp.sh"
else
echo -e "${YELLOW}Vendor-agnostic MCP setup script not found. Skipping MCP configuration setup.${NC}"
fi
# Set up all MCP servers (works in worktrees)
# EXPERIMENT #1213: Temporarily disabled - testing without MCP servers
# if [[ -f "$DOT_DEN/mcp/setup-all-mcp-servers.sh" ]]; then
# echo -e "${DIVIDER}"
# echo "Setting up MCP servers..."
# "$DOT_DEN/mcp/setup-all-mcp-servers.sh"
# else
# echo -e "${YELLOW}MCP server setup script not found. Skipping MCP server setup.${NC}"
# fi
# GitLab MCP authentication now handled by @zereight/mcp-gitlab package
# No additional auth setup needed beyond GITLAB_PERSONAL_ACCESS_TOKEN in ~/.bash_secrets
# GitLab MCP server works via GITLAB_PERSONAL_ACCESS_TOKEN - no glab CLI setup needed
# Configuration files setup complete
echo -e "${GREEN}✓ Configuration files setup complete${NC}"
# Platform-specific setup
echo -e "${DIVIDER}"
echo "Checking for platform-specific setup..."
# Check if this is running on Arch Linux and offer Arch-specific setup
if command -v pacman &>/dev/null; then
echo "Detected Arch Linux"
# Check if Arch Linux setup script exists
if [[ -f "$DOT_DEN/arch-linux/setup.sh" ]]; then
echo "Running Arch Linux specific setup..."
source "$DOT_DEN/arch-linux/setup.sh"
else
echo "No Arch Linux setup script found. Skipping Arch-specific setup."
fi
fi
# Check if this is a Raspberry Pi and run Pi-specific setup if needed
if grep -q "Raspberry Pi" /proc/cpuinfo 2>/dev/null; then
echo "Detected Raspberry Pi hardware"
# Check if Raspberry Pi setup script exists
if [[ -f "$DOT_DEN/raspberry-pi/setup.sh" ]]; then
echo "Running Raspberry Pi specific setup..."
source "$DOT_DEN/raspberry-pi/setup.sh"
else
echo "No Raspberry Pi setup script found. Skipping Pi-specific setup."
fi
fi
# Check if this is Linux Mint and configure desktop preferences
if [[ -f /etc/os-release ]] && grep -q "linuxmint" /etc/os-release; then
echo "Detected Linux Mint"
# Check if Linux Mint configuration script exists
if [[ -f "$DOT_DEN/utils/configure-linux-mint.sh" ]]; then
source "$DOT_DEN/utils/configure-linux-mint.sh"
configure_linux_mint
else
echo "No Linux Mint configuration script found. Skipping Linux Mint-specific setup."
fi
fi
# Tools setup
echo -e "${DIVIDER}"
echo "Setting up development tools..."
# Node.js setup with NVM (must run before CLI configuration to keep global tools available)
echo -e "${DIVIDER}"
echo "Setting up Node.js with NVM..."
# Fix npm prefix configuration conflict with nvm
if [ -f "$DOT_DEN/utils/fix-npm-nvm-conflict.sh" ]; then
bash "$DOT_DEN/utils/fix-npm-nvm-conflict.sh"
fi
# Ensure NVM directory exists
export NVM_DIR="$HOME/.nvm"
# Install NVM if not already installed
if [ ! -d "$NVM_DIR" ]; then
echo "Installing NVM (Node Version Manager)..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash >/dev/null 2>&1
# Source NVM immediately after installation
if [ -d "$NVM_DIR" ]; then
if [ -s "$NVM_DIR/nvm.sh" ]; then
# shellcheck source=/dev/null
. "$NVM_DIR/nvm.sh"
fi
if [ -s "$NVM_DIR/bash_completion" ]; then
# shellcheck source=/dev/null
. "$NVM_DIR/bash_completion"
fi
fi
# Install latest LTS version of Node.js and set as default
nvm install --lts >/dev/null 2>&1
nvm use --lts >/dev/null 2>&1
nvm alias default 'lts/*' >/dev/null 2>&1
NODE_VERSION=$(node -v 2>/dev/null || echo "unknown")
echo -e "${GREEN}✓ Node.js LTS version ${NODE_VERSION} installed and set as default${NC}"
else
# Source NVM if it exists
if [ -d "$NVM_DIR" ]; then
if [ -s "$NVM_DIR/nvm.sh" ]; then
# shellcheck source=/dev/null
. "$NVM_DIR/nvm.sh"
fi
if [ -s "$NVM_DIR/bash_completion" ]; then
# shellcheck source=/dev/null
. "$NVM_DIR/bash_completion"
fi
fi
# Check if NVM is available
if command -v nvm >/dev/null 2>&1; then
CURRENT_NODE_VERSION=$(node -v 2>/dev/null || echo "none")
LATEST_LTS=$(nvm version-remote --lts 2>/dev/null || echo "unknown")
# Remove 'v' prefix for version comparison
CURRENT_VERSION=${CURRENT_NODE_VERSION#v}
LATEST_VERSION=${LATEST_LTS#v}
# Check if current version is different from latest LTS
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ] && [ "$LATEST_VERSION" != "unknown" ]; then
echo "Updating Node.js from $CURRENT_NODE_VERSION to $LATEST_LTS..."
nvm install --lts >/dev/null 2>&1
nvm use --lts >/dev/null 2>&1
nvm alias default 'lts/*' >/dev/null 2>&1
NEW_VERSION=$(node -v)
echo -e "${GREEN}✓ Node.js updated to latest LTS version: ${NEW_VERSION}${NC}"
else
echo -e "${GREEN}✓ Node.js is already up to date (${CURRENT_NODE_VERSION})${NC}"
fi
else
echo -e "${YELLOW}NVM installation found but not working properly. Reinstalling...${NC}"
rm -rf "$NVM_DIR"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash >/dev/null 2>&1
if [ -d "$NVM_DIR" ]; then
if [ -s "$NVM_DIR/nvm.sh" ]; then
# shellcheck source=/dev/null
. "$NVM_DIR/nvm.sh"
fi
if [ -s "$NVM_DIR/bash_completion" ]; then
# shellcheck source=/dev/null
. "$NVM_DIR/bash_completion"
fi
fi
nvm install --lts >/dev/null 2>&1
nvm use --lts >/dev/null 2>&1
nvm alias default 'lts/*' >/dev/null 2>&1
NODE_VERSION=$(node -v 2>/dev/null || echo "unknown")
echo -e "${GREEN}✓ Node.js LTS version ${NODE_VERSION} installed and set as default${NC}"
fi
fi
# Amazon Q removed - was breaking tmux by hijacking shell sessions with qterm
# Claude Code Configuration (includes trivial npm install)
echo -e "${DIVIDER}"
echo "Configuring Claude Code..."
# Verify npm is available before proceeding
if ! command -v npm >/dev/null 2>&1; then
echo -e "${YELLOW}npm not available. Skipping Claude Code configuration.${NC}"
else
if [[ -f "$DOT_DEN/utils/configure-claude-code.sh" ]]; then
source "$DOT_DEN/utils/configure-claude-code.sh"
configure_claude_code || {
echo -e "${YELLOW}Claude Code configuration incomplete. Run configure-claude-code.sh manually.${NC}"
}
fi
fi
# Symlink Claude Code settings to correct location
# Claude Code terminology: ~/.claude/settings.json = "user settings" (their term for global)
# We call these "global settings" since they apply across all your projects
# Using .claude/settings.json (not .local) prevents Claude from overwriting on startup
if [[ -f "$DOT_DEN/.claude/settings.json" ]]; then
echo "Creating symlink for Claude Code global settings..."
# Create ~/.claude directory if it doesn't exist
mkdir -p "$HOME/.claude"
# Create symlink (force to overwrite if exists)
ln -sf "$DOT_DEN/.claude/settings.json" "$HOME/.claude/settings.json"
echo -e "${GREEN}✓ Claude Code global settings symlinked to ~/.claude/settings.json${NC}"
else
echo -e "${YELLOW}Warning: .claude/settings.json not found. Skipping settings symlink.${NC}"
fi
# Symlink Claude Desktop MCP config to unified location (experiment #1213)
if [[ -f "$DOT_DEN/mcp/mcp.json" ]]; then
echo "Creating symlink for Claude Desktop MCP config..."
# Create ~/.config/claude directory if it doesn't exist
mkdir -p "$HOME/.config/claude"
# Create symlink to unified MCP config
ln -sf "$DOT_DEN/mcp/mcp.json" "$HOME/.config/claude/claude_desktop_config.json"
echo -e "${GREEN}✓ Claude Desktop MCP config symlinked to mcp/mcp.json${NC}"
fi
# OpenAI Codex Configuration (includes trivial npm install)
echo -e "${DIVIDER}"
echo "Configuring OpenAI Codex..."
# Verify npm is available before proceeding
if ! command -v npm >/dev/null 2>&1; then
echo -e "${YELLOW}npm not available. Skipping Codex configuration.${NC}"
else
if [[ -f "$DOT_DEN/utils/configure-codex.sh" ]]; then
bash "$DOT_DEN/utils/configure-codex.sh" || {
echo -e "${YELLOW}Codex configuration incomplete. Run configure-codex.sh manually.${NC}"
}
fi
fi
# Install uv for Python package management
if ! command -v uv >/dev/null 2>&1; then
echo "Installing uv package manager..."
curl -Ls https://astral.sh/uv/install.sh | sh >/dev/null 2>&1
# Check if PATH already contains the .local/bin entry before adding
if ! grep -q "export PATH=\"\\$HOME/.local/bin:\\$PATH\"" "$HOME/.bashrc"; then
echo "export PATH=\"$HOME/.local/bin:\$PATH\"" >> "$HOME/.bashrc"
fi
# Make uv available in the current shell
export PATH="$HOME/.local/bin:$PATH"
echo -e "${GREEN}✓ uv package manager installed${NC}"
fi
# GitHub CLI setup
echo -e "${DIVIDER}"
echo "Setting up GitHub CLI..."
if [[ -f "$DOT_DEN/utils/install-gh-cli.sh" ]]; then
source "$DOT_DEN/utils/install-gh-cli.sh"
setup_gh_cli || {
echo -e "${RED}Failed to setup GitHub CLI completely. Some features may not work.${NC}"
echo "You can install it manually later or run the setup script again."
}
else
echo -e "${RED}GitHub CLI installation script not found at $DOT_DEN/utils/install-gh-cli.sh${NC}"
echo "To use GitHub MCP features, install GitHub CLI and run: export GITHUB_TOKEN=\$(gh auth token)"
fi
# Git Delta setup
echo -e "${DIVIDER}"
echo "Checking Git Delta setup..."
# Check if Git Delta is referenced in gitconfig
if grep -q "delta" ~/.gitconfig 2>/dev/null; then
echo "Git Delta is referenced in your gitconfig."
# Check if Git Delta is installed
if command -v delta &> /dev/null; then
echo -e "${GREEN}✓ Git Delta is already installed${NC}"
else
echo "Git Delta is not installed. Installing now..."
if [ -f "$DOT_DEN/utils/install-git-delta.sh" ]; then
bash "$DOT_DEN/utils/install-git-delta.sh"
else
echo -e "${RED}Git Delta installation script not found.${NC}"
echo "Please install Git Delta manually or your git diff commands may fail."
fi
fi
else
echo "Git Delta is not referenced in your gitconfig. Skipping installation."
fi
# Docker setup
echo -e "${DIVIDER}"
echo "Checking Docker setup..."
# Check if Docker is already installed
if command -v docker &> /dev/null; then
echo -e "${GREEN}✓ Docker is already installed${NC}"
else
# Source and run Docker installation script
if [[ -f "$DOT_DEN/utils/install-docker.sh" ]]; then
source "$DOT_DEN/utils/install-docker.sh"
install_docker || {
echo -e "${RED}Docker installation failed.${NC}"
echo "Please try installing Docker manually for your system."
}
else
echo -e "${RED}Docker installation script not found at $DOT_DEN/utils/install-docker.sh${NC}"
echo "Please check your dotfiles installation."
fi
fi
# tmux setup
echo -e "${DIVIDER}"
echo "Setting up tmux..."
if [[ -f "$DOT_DEN/utils/install-tmux.sh" ]]; then
source "$DOT_DEN/utils/install-tmux.sh"
install_or_update_tmux || {
echo -e "${RED}Failed to setup tmux completely. Some features may not work.${NC}"
echo "You can install it manually later using your system's package manager."
}
else
echo -e "${RED}tmux installation script not found at $DOT_DEN/utils/install-tmux.sh${NC}"
fi
echo -e "${DIVIDER}"
# urlview setup (for tmux URL extraction)
echo "Setting up urlview (tmux URL extraction utility)..."
if [[ -f "$DOT_DEN/utils/install-urlview.sh" ]]; then
source "$DOT_DEN/utils/install-urlview.sh"
install_or_update_urlview || {
echo -e "${YELLOW}Failed to setup urlview. tmux URL extraction may not work.${NC}"
echo "You can install it manually: apt install urlview (Linux) or brew install urlview (macOS)"
}
else
echo -e "${RED}urlview installation script not found at $DOT_DEN/utils/install-urlview.sh${NC}"
fi
# Check if user is in docker group (Linux only)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if groups | grep -q docker; then
echo -e "${GREEN}✓ User is in the docker group${NC}"
else
echo -e "${YELLOW}User is not in the docker group.${NC}"
echo "To add yourself to the docker group, run:"
echo -e "${GREEN}sudo usermod -aG docker \$USER${NC}"
echo "Then log out and back in for changes to take effect."
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "${BLUE}Docker Desktop on macOS doesn't require group membership${NC}"
fi
# Test Docker if it's installed (without sudo)
if command -v docker &> /dev/null; then
echo "Testing Docker access..."
if docker info &>/dev/null; then
echo -e "${GREEN}✓ Docker is working correctly${NC}"
else
echo -e "${YELLOW}Docker is installed but not accessible without sudo.${NC}"
echo "Please log out and back in, or restart your system to apply group changes."
echo "Continuing with setup..."
fi
fi
# Source bash aliases to make them immediately available
echo "Loading bash aliases into current session..."
if [[ -f ~/.bash_aliases ]]; then
# shellcheck disable=SC1090
source ~/.bash_aliases
echo -e "${GREEN}✓ Bash aliases loaded successfully${NC}"
fi
# Configure git hooks
if [[ -d "$DOT_DEN/.githooks" ]]; then
echo "Configuring git hooks..."
# Set the git hooks path for the dotfiles repository
(cd "$DOT_DEN" && git config core.hooksPath .githooks)
echo -e "${GREEN}✓ Git hooks configured${NC}"
else
echo -e "${YELLOW}Git hooks directory not found. Skipping hooks configuration.${NC}"
fi
echo -e "${DIVIDER}"
echo -e "${GREEN}✅ Dotfiles setup complete!${NC}"
echo "Your development environment is now configured and ready to use."
echo -e "${DIVIDER}"
# Clear the error trap to prevent it from persisting in the shell session
trap - ERR
# Final debug message
echo "Debug: Setup script completed successfully"