-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·261 lines (221 loc) · 9.33 KB
/
install.sh
File metadata and controls
executable file
·261 lines (221 loc) · 9.33 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
#!/usr/bin/env bash
# =============================================================================
# Dotfiles Installation Script
# =============================================================================
# Cross-platform script to symlink dotfiles to home directory.
# Works on macOS, Linux, and GitHub Codespaces.
#
# Usage: ./install.sh [--force]
#
# Options:
# --force Overwrite existing files without creating backups
# =============================================================================
set -euo pipefail
IFS=$'\n\t'
# -----------------------------------------------------------------------------
# Configuration
# -----------------------------------------------------------------------------
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
OS="$(uname -s)"
FORCE_MODE=false
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
# Parse arguments
for arg in "$@"; do
case $arg in
--force) FORCE_MODE=true ;;
esac
done
# -----------------------------------------------------------------------------
# Helper Functions
# -----------------------------------------------------------------------------
# Colors
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly YELLOW='\033[0;33m'
readonly BLUE='\033[0;34m'
readonly MAGENTA='\033[0;35m'
readonly CYAN='\033[0;36m'
readonly BOLD='\033[1m'
readonly DIM='\033[2m'
readonly RESET='\033[0m'
info() {
printf "${BLUE} ℹ${RESET} %s\n" "$1"
}
success() {
printf "${GREEN} ✓${RESET} %s\n" "$1"
}
warn() {
printf "${YELLOW} ⚠${RESET} %s\n" "$1"
}
error() {
printf "${RED} ✗${RESET} %s\n" "$1" >&2
}
# Print section header
section() {
local title="$1"
echo ""
printf "${BOLD}${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n"
printf "${BOLD}${CYAN} ${RESET} ${BOLD}%s${RESET}\n" "$title"
printf "${BOLD}${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}\n"
echo ""
}
# Create symlink with backup of existing files
link_file() {
local src="$1"
local dest="$2"
# Skip if source doesn't exist
if [[ ! -e "$src" ]]; then
warn "Source not found, skipping: $src"
return 0
fi
# Create parent directory if needed
mkdir -p "$(dirname "$dest")"
# Handle existing files/symlinks
if [[ -e "$dest" || -L "$dest" ]]; then
# Check if already correctly linked
if [[ -L "$dest" ]]; then
local current_target
current_target="$(readlink "$dest")"
if [[ "$current_target" == "$src" ]]; then
success "Already linked: $dest"
return 0
fi
fi
if [[ "$FORCE_MODE" == true ]]; then
# Force mode: remove existing file
rm -rf "$dest"
info "Removed existing: $dest"
else
# Backup existing file
local backup="${dest}.backup.$(date +%Y%m%d%H%M%S)"
warn "Backing up existing file: $dest → $backup"
mv "$dest" "$backup"
fi
fi
# Create symlink
ln -s "$src" "$dest"
success "Linked: $dest → $src"
}
# -----------------------------------------------------------------------------
# Symlink Definitions
# -----------------------------------------------------------------------------
# Define symlinks as arrays: source (relative to dotfiles) and destination
# Common files (all platforms)
declare -a COMMON_LINKS=(
# Zsh configuration
".zshrc:$HOME/.zshrc"
".zshenv:$HOME/.zshenv"
".zprofile:$HOME/.zprofile"
".zsh:$HOME/.zsh"
# Git configuration
".gitconfig:$HOME/.gitconfig"
# Starship prompt
".config/starship:$XDG_CONFIG_HOME/starship"
# Fastfetch system info
".config/fastfetch:$XDG_CONFIG_HOME/fastfetch"
)
# macOS-only files
declare -a MACOS_LINKS=(
# 1Password SSH agent configuration
".config/1Password/ssh/agent.toml:$XDG_CONFIG_HOME/1Password/ssh/agent.toml"
# SSH configuration (uses 1Password agent on macOS)
".ssh/config:$HOME/.ssh/config"
".ssh/1Password/config:$HOME/.ssh/1Password/config"
)
# Linux-only files (including Codespaces)
declare -a LINUX_LINKS=(
# Add Linux-specific symlinks here
# SSH config without 1Password agent for Codespaces
)
# Codespaces-specific files
declare -a CODESPACES_LINKS=(
# Add Codespaces-specific symlinks here
)
# -----------------------------------------------------------------------------
# Main Installation
# -----------------------------------------------------------------------------
echo ""
printf "${BOLD}${MAGENTA}╔══════════════════════════════════════════════════════════════════════════════╗${RESET}\n"
printf "${BOLD}${MAGENTA}║${RESET} ${BOLD}${MAGENTA}║${RESET}\n"
printf "${BOLD}${MAGENTA}║${RESET} ${BOLD}🔗 Dotfiles Installation${RESET} ${BOLD}${MAGENTA}║${RESET}\n"
printf "${BOLD}${MAGENTA}║${RESET} ${BOLD}${MAGENTA}║${RESET}\n"
printf "${BOLD}${MAGENTA}╚══════════════════════════════════════════════════════════════════════════════╝${RESET}\n"
echo ""
printf " ${DIM}Dotfiles:${RESET} %s\n" "$DOTFILES_DIR"
printf " ${DIM}System:${RESET} %s\n" "$OS"
[[ -n "${CODESPACES:-}" ]] && printf " ${DIM}Environment:${RESET} GitHub Codespaces\n"
[[ "$FORCE_MODE" == true ]] && warn "Force mode enabled - existing files will be overwritten"
# -----------------------------------------------------------------------------
# Install Common Symlinks
# -----------------------------------------------------------------------------
section "Common Dotfiles"
for link in "${COMMON_LINKS[@]}"; do
src="${DOTFILES_DIR}/${link%%:*}"
dest="${link#*:}"
link_file "$src" "$dest"
done
# -----------------------------------------------------------------------------
# Install OS-Specific Symlinks
# -----------------------------------------------------------------------------
if [[ "$OS" == "Darwin" ]]; then
section "macOS-Specific Dotfiles"
for link in "${MACOS_LINKS[@]}"; do
src="${DOTFILES_DIR}/${link%%:*}"
dest="${link#*:}"
link_file "$src" "$dest"
done
elif [[ "$OS" == "Linux" ]]; then
section "Linux-Specific Dotfiles"
for link in "${LINUX_LINKS[@]}"; do
src="${DOTFILES_DIR}/${link%%:*}"
dest="${link#*:}"
link_file "$src" "$dest"
done
# Codespaces-specific
if [[ -n "${CODESPACES:-}" ]]; then
section "Codespaces-Specific Dotfiles"
for link in "${CODESPACES_LINKS[@]}"; do
src="${DOTFILES_DIR}/${link%%:*}"
dest="${link#*:}"
link_file "$src" "$dest"
done
fi
fi
# -----------------------------------------------------------------------------
# Post-Installation Tasks
# -----------------------------------------------------------------------------
section "Post-Installation Checks"
# Create .config directory if it doesn't exist
mkdir -p "$XDG_CONFIG_HOME"
# Ensure .zsh directory scripts are sourced correctly
if [[ -d "$HOME/.zsh" ]]; then
success "Zsh configuration directory is in place"
fi
# Check if starship is installed
if command -v starship &>/dev/null; then
success "Starship prompt is installed"
else
warn "Starship not installed. Install with: brew install starship (macOS) or cargo install starship (Linux)"
fi
# -----------------------------------------------------------------------------
# Setup Complete
# -----------------------------------------------------------------------------
echo ""
printf "${BOLD}${GREEN}╔══════════════════════════════════════════════════════════════════════════════╗${RESET}\n"
printf "${BOLD}${GREEN}║${RESET} ${BOLD}${GREEN}║${RESET}\n"
printf "${BOLD}${GREEN}║${RESET} ${BOLD}✓ Dotfiles installation complete!${RESET} ${BOLD}${GREEN}║${RESET}\n"
printf "${BOLD}${GREEN}║${RESET} ${BOLD}${GREEN}║${RESET}\n"
printf "${BOLD}${GREEN}╚══════════════════════════════════════════════════════════════════════════════╝${RESET}\n"
echo ""
# Show next steps based on OS
if [[ "$OS" == "Darwin" ]]; then
info "Next steps for macOS:"
echo " Restart your terminal or run: source ~/.zshrc"
elif [[ -n "${CODESPACES:-}" ]]; then
info "Codespaces setup complete!"
echo " Your shell will be configured on next terminal launch."
else
info "Next steps for Linux:"
echo " Restart your terminal or run: source ~/.zshrc"
fi
echo ""