-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·814 lines (706 loc) · 23.1 KB
/
install.sh
File metadata and controls
executable file
·814 lines (706 loc) · 23.1 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
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
#!/usr/bin/env bash
# Dotfiles installation script using GNU Stow.
# Usage: ./install.sh [options] [packages...]
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
DOTFILES_DIR="${SCRIPT_DIR}/dotfiles"
# Package definitions
PACKAGES_ALL=(zsh tmux vim git gh nvim ripgrep editorconfig)
PACKAGES_MINIMAL=(zsh vim git)
# Default to all packages
PACKAGES=("${PACKAGES_ALL[@]}")
# Verbose logging (off by default)
VERBOSE=false
usage() {
cat <<EOF
Usage: $0 [OPTIONS] [PACKAGES...]
Install dotfiles using GNU Stow.
OPTIONS:
-h, --help Show this help message
-l, --list List available packages
-a, --all Install all packages (default)
-r, --remove Remove (unstow) packages
-n, --no-omz Skip oh-my-zsh installation
-v, --verbose Show detailed logging output
--minimal Install minimal profile (zsh, vim, git)
--full Install full profile (all packages, default)
--shellcheck Lint all shell scripts
PROFILES:
minimal: ${PACKAGES_MINIMAL[*]}
full: ${PACKAGES_ALL[*]}
PACKAGES:
${PACKAGES_ALL[*]}
If no packages specified, the full profile will be installed.
EXAMPLES:
$0 # Install all packages (full profile)
$0 --minimal # Install minimal profile
$0 zsh nvim # Install only zsh and nvim
$0 -r zsh # Remove zsh package
$0 --no-omz # Install all but skip oh-my-zsh setup
EOF
}
print_success() {
printf "\e[0;32m [✔] %s\e[0m\n" "$1"
}
print_error() {
printf "\e[0;31m [✖] %s\e[0m\n" "$1"
}
print_info() {
printf "\e[0;34m [i] %s\e[0m\n" "$1"
}
log_verbose() {
if [[ "${VERBOSE}" == true ]]; then
printf "\e[0;90m %s\e[0m\n" "$1"
fi
}
detect_pkg_manager() {
if command -v apt &>/dev/null; then
echo "apt"
elif command -v brew &>/dev/null; then
echo "brew"
elif command -v pacman &>/dev/null; then
echo "pacman"
elif command -v dnf &>/dev/null; then
echo "dnf"
else
echo ""
fi
}
install_stow() {
print_info "Installing GNU Stow..."
local mgr
mgr=$(detect_pkg_manager)
log_verbose "Detected package manager: ${mgr:-none}"
if [[ "${mgr}" == "apt" ]]; then
log_verbose "Running: sudo apt update && sudo apt install -y stow"
sudo apt update && sudo apt install -y stow
elif [[ "${mgr}" == "brew" ]]; then
log_verbose "Running: brew install stow"
brew install stow
elif [[ "${mgr}" == "pacman" ]]; then
log_verbose "Running: sudo pacman -S --noconfirm stow"
sudo pacman -S --noconfirm stow
elif [[ "${mgr}" == "dnf" ]]; then
log_verbose "Running: sudo dnf install -y stow"
sudo dnf install -y stow
else
print_error "Could not detect package manager. Install stow manually."
exit 1
fi
if command -v stow &>/dev/null; then
log_verbose "stow binary: $(command -v stow)"
print_success "Installed stow"
else
print_error "Failed to install stow"
exit 1
fi
}
check_stow() {
if ! command -v stow &>/dev/null; then
log_verbose "stow not found in PATH, installing..."
install_stow
else
log_verbose "stow already available: $(command -v stow)"
fi
}
pkg_install() {
local pkg=$1
local mgr
mgr=$(detect_pkg_manager)
log_verbose "Installing system package '${pkg}' via ${mgr:-unknown}"
if [[ "${mgr}" == "apt" ]]; then
sudo apt update -qq && sudo apt install -y "$pkg"
elif [[ "${mgr}" == "brew" ]]; then
brew install "$pkg"
elif [[ "${mgr}" == "pacman" ]]; then
sudo pacman -S --noconfirm "$pkg"
elif [[ "${mgr}" == "dnf" ]]; then
sudo dnf install -y "$pkg"
else
print_error "Could not detect package manager. Install ${pkg} manually."
return 1
fi
}
install_make() {
if command -v make &>/dev/null; then
print_info "make already installed: $(make --version | head -1)"
return 0
fi
print_info "Installing make..."
pkg_install make
if command -v make &>/dev/null; then
print_success "Installed $(make --version | head -1)"
else
print_error "Failed to install make"
return 1
fi
}
install_tmux() {
if command -v tmux &>/dev/null; then
print_info "tmux already installed: $(tmux -V)"
return 0
fi
print_info "Installing tmux..."
pkg_install tmux
if command -v tmux &>/dev/null; then
print_success "Installed $(tmux -V)"
else
print_error "Failed to install tmux"
return 1
fi
}
install_ripgrep() {
if command -v rg &>/dev/null; then
print_info "ripgrep already installed: $(rg --version | head -1)"
return 0
fi
print_info "Installing ripgrep..."
pkg_install ripgrep
if command -v rg &>/dev/null; then
print_success "Installed $(rg --version | head -1)"
else
print_error "Failed to install ripgrep"
return 1
fi
}
install_omz() {
print_info "Setting up oh-my-zsh..."
ZSH="${HOME}/.oh-my-zsh"
ZSH_CUSTOM="${ZSH_CUSTOM:-${ZSH}/custom}"
# Clone or update Oh My Zsh.
log_verbose "ZSH dir: ${ZSH}"
log_verbose "ZSH_CUSTOM dir: ${ZSH_CUSTOM}"
if [[ ! -d "${ZSH}" ]]; then
log_verbose "Cloning oh-my-zsh into ${ZSH}"
git clone --quiet --filter=blob:none https://github.com/robbyrussell/oh-my-zsh "${ZSH}"
print_success "Installed oh-my-zsh"
else
log_verbose "Updating existing oh-my-zsh at ${ZSH}"
git -C "${ZSH}" pull --quiet
print_success "Updated oh-my-zsh"
fi
# Clone or update Powerlevel10k.
THEME_REPO_URL="https://github.com/romkatv/powerlevel10k"
THEME_PATH="${ZSH_CUSTOM}/themes/${THEME_REPO_URL##*/}"
THEME_VERSION_TAG="master"
if command -v jq &>/dev/null; then
THEME_VERSION_TAG=$(curl -s https://api.github.com/repos/romkatv/powerlevel10k/releases/latest | jq -r .tag_name)
fi
log_verbose "Powerlevel10k version: ${THEME_VERSION_TAG}, path: ${THEME_PATH}"
if [[ ! -d "${THEME_PATH}" ]]; then
log_verbose "Cloning powerlevel10k from ${THEME_REPO_URL}"
git clone --quiet --filter=blob:none --branch "${THEME_VERSION_TAG}" "${THEME_REPO_URL}" "${THEME_PATH}"
print_success "Installed powerlevel10k"
else
log_verbose "Updating existing powerlevel10k at ${THEME_PATH}"
git -C "${THEME_PATH}" fetch --quiet
git -C "${THEME_PATH}" checkout "${THEME_VERSION_TAG}" --quiet
print_success "Updated powerlevel10k"
fi
# Install or update custom oh-my-zsh plugins.
CUSTOM_PLUGIN_REPOS=(
"https://github.com/Aloxaf/fzf-tab"
"https://github.com/zdharma-continuum/fast-syntax-highlighting"
"https://github.com/zsh-users/zsh-autosuggestions"
)
for REPO_URL in "${CUSTOM_PLUGIN_REPOS[@]}"; do
PLUGIN_NAME="${REPO_URL##*/}"
PLUGIN_PATH="${ZSH_CUSTOM}/plugins/${PLUGIN_NAME}"
log_verbose "Plugin ${PLUGIN_NAME}: repo=${REPO_URL} path=${PLUGIN_PATH}"
if [[ ! -d "${PLUGIN_PATH}" ]]; then
log_verbose "Cloning ${PLUGIN_NAME} into ${PLUGIN_PATH}"
git clone --quiet --filter=blob:none "${REPO_URL}" "${PLUGIN_PATH}"
print_success "Installed plugin: ${PLUGIN_NAME}"
else
log_verbose "Pulling latest for ${PLUGIN_NAME}"
git -C "${PLUGIN_PATH}" pull --quiet
print_success "Updated plugin: ${PLUGIN_NAME}"
fi
done
}
install_fd() {
if command -v fd &>/dev/null; then
print_info "fd already installed: $(fd --version)"
return 0
fi
print_info "Installing fd..."
local version
version=$(curl -s https://api.github.com/repos/sharkdp/fd/releases/latest | grep -oP '"tag_name":\s*"v\K[^"]+')
local url="https://github.com/sharkdp/fd/releases/download/v${version}/fd-v${version}-x86_64-unknown-linux-gnu.tar.gz"
local tmp_dir
tmp_dir=$(mktemp -d)
log_verbose "fd version: ${version}"
log_verbose "Download URL: ${url}"
log_verbose "Temp dir: ${tmp_dir}"
if curl -fsSL "${url}" -o "${tmp_dir}/fd.tar.gz"; then
tar -xzf "${tmp_dir}/fd.tar.gz" -C "${tmp_dir}" --strip-components=1
sudo mv "${tmp_dir}/fd" /usr/local/bin/fd
rm -rf "${tmp_dir}"
print_success "Installed fd $(fd --version)"
else
rm -rf "${tmp_dir}"
print_error "Failed to download fd"
return 1
fi
}
install_bat() {
if command -v bat &>/dev/null || command -v batcat &>/dev/null; then
print_info "bat already installed"
return 0
fi
print_info "Installing bat..."
local version
version=$(curl -s https://api.github.com/repos/sharkdp/bat/releases/latest | grep -oP '"tag_name":\s*"v\K[^"]+')
local url="https://github.com/sharkdp/bat/releases/download/v${version}/bat-v${version}-x86_64-unknown-linux-gnu.tar.gz"
local tmp_dir
tmp_dir=$(mktemp -d)
log_verbose "bat version: ${version}"
log_verbose "Download URL: ${url}"
log_verbose "Temp dir: ${tmp_dir}"
if curl -fsSL "${url}" -o "${tmp_dir}/bat.tar.gz"; then
tar -xzf "${tmp_dir}/bat.tar.gz" -C "${tmp_dir}" --strip-components=1
sudo mv "${tmp_dir}/bat" /usr/local/bin/bat
rm -rf "${tmp_dir}"
print_success "Installed bat $(bat --version)"
else
rm -rf "${tmp_dir}"
print_error "Failed to download bat"
return 1
fi
}
install_lazygit() {
if command -v lazygit &>/dev/null; then
print_info "lazygit already installed: $(lazygit --version | head -1)"
return 0
fi
print_info "Installing lazygit..."
local version
version=$(curl -s https://api.github.com/repos/jesseduffield/lazygit/releases/latest | grep -oP '"tag_name":\s*"v\K[^"]+')
local url="https://github.com/jesseduffield/lazygit/releases/download/v${version}/lazygit_${version}_Linux_x86_64.tar.gz"
local tmp_dir
tmp_dir=$(mktemp -d)
log_verbose "lazygit version: ${version}"
log_verbose "Download URL: ${url}"
log_verbose "Temp dir: ${tmp_dir}"
if curl -fsSL "${url}" -o "${tmp_dir}/lazygit.tar.gz"; then
tar -xzf "${tmp_dir}/lazygit.tar.gz" -C "${tmp_dir}"
sudo mv "${tmp_dir}/lazygit" /usr/local/bin/lazygit
rm -rf "${tmp_dir}"
print_success "Installed lazygit $(lazygit --version | head -1)"
else
rm -rf "${tmp_dir}"
print_error "Failed to download lazygit"
return 1
fi
}
install_gh() {
if command -v gh &>/dev/null; then
print_info "gh already installed: $(gh --version | head -1)"
return 0
fi
print_info "Installing GitHub CLI (gh)..."
local mgr
mgr=$(detect_pkg_manager)
log_verbose "Detected package manager: ${mgr:-none}"
if [[ "${mgr}" == "brew" ]]; then
brew install gh
elif [[ "${mgr}" == "apt" ]]; then
sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
| sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
| sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update && sudo apt install -y gh
elif [[ "${mgr}" == "pacman" ]]; then
sudo pacman -S --noconfirm github-cli
elif [[ "${mgr}" == "dnf" ]]; then
sudo dnf install -y gh
else
print_error "Could not detect package manager. Install gh manually: https://cli.github.com"
return 1
fi
if command -v gh &>/dev/null; then
print_success "Installed $(gh --version | head -1)"
else
print_error "Failed to install gh"
return 1
fi
}
install_yq() {
if command -v yq &>/dev/null; then
print_info "yq already installed: $(yq --version)"
return 0
fi
print_info "Installing yq..."
local version
version=$(curl -s https://api.github.com/repos/mikefarah/yq/releases/latest | grep -oP '"tag_name":\s*"v\K[^"]+')
local url="https://github.com/mikefarah/yq/releases/download/v${version}/yq_linux_amd64"
local tmp_dir
tmp_dir=$(mktemp -d)
log_verbose "yq version: ${version}"
log_verbose "Download URL: ${url}"
log_verbose "Temp dir: ${tmp_dir}"
if curl -fsSL "${url}" -o "${tmp_dir}/yq"; then
chmod +x "${tmp_dir}/yq"
sudo mv "${tmp_dir}/yq" /usr/local/bin/yq
rm -rf "${tmp_dir}"
print_success "Installed yq $(yq --version)"
else
rm -rf "${tmp_dir}"
print_error "Failed to download yq"
return 1
fi
}
install_eza() {
if command -v eza &>/dev/null; then
print_info "eza already installed: $(eza --version | head -1)"
return 0
fi
print_info "Installing eza..."
local latest_url="https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz"
local tmp_dir
tmp_dir=$(mktemp -d)
log_verbose "Download URL: ${latest_url}"
log_verbose "Temp dir: ${tmp_dir}"
if curl -fsSL "${latest_url}" -o "${tmp_dir}/eza.tar.gz"; then
tar -xzf "${tmp_dir}/eza.tar.gz" -C "${tmp_dir}"
sudo mv "${tmp_dir}/eza" /usr/local/bin/eza
rm -rf "${tmp_dir}"
print_success "Installed eza $(eza --version | head -1)"
else
rm -rf "${tmp_dir}"
print_error "Failed to download eza"
return 1
fi
}
install_fzf() {
print_info "Setting up fzf..."
FZF_DIR="${HOME}/.fzf"
log_verbose "fzf dir: ${FZF_DIR}"
if [[ ! -d "${FZF_DIR}" ]]; then
log_verbose "Cloning fzf into ${FZF_DIR}"
git clone --quiet --depth 1 https://github.com/junegunn/fzf.git "${FZF_DIR}"
print_success "Cloned fzf"
else
log_verbose "Pulling latest fzf"
git -C "${FZF_DIR}" pull --quiet
print_success "Updated fzf"
fi
# Install fzf binary and shell integrations (non-interactively)
log_verbose "Running fzf installer: ${FZF_DIR}/install --bin --no-bash --no-zsh --no-fish"
"${FZF_DIR}/install" --bin --no-bash --no-zsh --no-fish >/dev/null 2>&1
print_success "Installed fzf binary"
}
install_nvim() {
print_info "Installing latest Neovim..."
if command -v nvim &>/dev/null; then
local current_version
current_version=$(nvim --version | head -1 | grep -oP 'v\K[0-9.]+')
print_info "Current Neovim version: ${current_version}"
fi
local latest_url="https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz"
local tmp_dir
tmp_dir=$(mktemp -d)
log_verbose "Download URL: ${latest_url}"
log_verbose "Temp dir: ${tmp_dir}"
if curl -fsSL "${latest_url}" -o "${tmp_dir}/nvim.tar.gz"; then
log_verbose "Extracting Neovim archive"
tar -xzf "${tmp_dir}/nvim.tar.gz" -C "${tmp_dir}"
log_verbose "Installing to /opt/nvim"
sudo rm -rf /opt/nvim
sudo mv "${tmp_dir}/nvim-linux-x86_64" /opt/nvim
# Create symlink if not already on PATH via /opt/nvim/bin
log_verbose "Creating symlink: /usr/local/bin/nvim -> /opt/nvim/bin/nvim"
sudo ln -sf /opt/nvim/bin/nvim /usr/local/bin/nvim
rm -rf "${tmp_dir}"
print_success "Installed Neovim $(nvim --version | head -1)"
else
rm -rf "${tmp_dir}"
print_error "Failed to download Neovim"
return 1
fi
}
install_node() {
local need_install=false
if ! command -v node &>/dev/null; then
need_install=true
else
local node_major
node_major=$(node -v | grep -oP 'v\K[0-9]+')
if (( node_major < 18 )); then
print_info "Node.js v${node_major} is too old (need >= 18), upgrading..."
need_install=true
elif ! npm --version &>/dev/null; then
print_info "Node.js $(node -v) found but npm is broken, reinstalling..."
need_install=true
else
print_info "Node.js already installed: $(node -v), npm: $(npm --version)"
return 0
fi
fi
if [[ "${need_install}" == true ]]; then
print_info "Installing Node.js LTS..."
local mgr
mgr=$(detect_pkg_manager)
log_verbose "Detected package manager: ${mgr:-none}"
if [[ "${mgr}" == "apt" ]]; then
# Purge all existing Node.js / npm packages to avoid version conflicts
log_verbose "Purging existing Node.js and npm packages"
sudo apt purge -y nodejs npm libnode-dev libnode72 nodejs-doc 2>/dev/null || true
sudo apt autoremove -y 2>/dev/null || true
# Remove stale distro npm that can conflict with NodeSource
if [[ -d /usr/share/nodejs/npm ]]; then
log_verbose "Removing stale /usr/share/nodejs/npm"
sudo rm -rf /usr/share/nodejs/npm
fi
log_verbose "Adding NodeSource LTS repository"
curl -fsSL "https://deb.nodesource.com/setup_lts.x" | sudo -E bash -
sudo apt install -y nodejs
elif [[ "${mgr}" == "brew" ]]; then
brew install node
elif [[ "${mgr}" == "pacman" ]]; then
sudo pacman -S --noconfirm nodejs npm
elif [[ "${mgr}" == "dnf" ]]; then
sudo dnf install -y nodejs npm
else
print_error "Could not detect package manager. Install Node.js LTS manually."
return 1
fi
if command -v node &>/dev/null && npm --version &>/dev/null; then
print_success "Installed Node.js $(node -v) with npm $(npm --version)"
else
print_error "Failed to install Node.js"
return 1
fi
fi
}
install_tpm() {
print_info "Setting up TPM (Tmux Plugin Manager)..."
TPM_DIR="${HOME}/.tmux/plugins/tpm"
log_verbose "TPM dir: ${TPM_DIR}"
if [[ ! -d "${TPM_DIR}" ]]; then
log_verbose "Cloning TPM into ${TPM_DIR}"
mkdir -p "${HOME}/.tmux/plugins"
git clone --quiet --filter=blob:none https://github.com/tmux-plugins/tpm "${TPM_DIR}"
print_success "Installed TPM"
else
git -C "${TPM_DIR}" pull --quiet
print_success "Updated TPM"
fi
# Install plugins automatically (runs outside tmux)
print_info "Installing tmux plugins..."
# TPM resolves the plugin path via `tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH`.
# Outside a session that variable doesn't exist yet, so set it before invoking TPM.
tmux start-server \; set-environment -g TMUX_PLUGIN_MANAGER_PATH "${HOME}/.tmux/plugins/" 2>/dev/null || true
"${TPM_DIR}/bin/install_plugins"
print_success "Installed tmux plugins"
}
stow_package() {
local package=$1
local action=$2
log_verbose "stow_package: package=${package} action=${action}"
if [[ ! -d "${DOTFILES_DIR}/${package}" ]]; then
log_verbose "No dotfiles directory for ${package}, skipping stow"
return 0
fi
# Skip stowing claude if its settings symlink already exists — the
# workspace installer manages this separately.
if [[ "${package}" == "claude" && -L "${HOME}/.claude/settings.json" ]]; then
print_success "Installed ${package}"
return 0
fi
# Ensure ~/.config exists for packages that need it
if [[ -d "${DOTFILES_DIR}/${package}/.config" ]]; then
log_verbose "Creating ${HOME}/.config (needed by ${package})"
mkdir -p "${HOME}/.config"
fi
if [[ "${action}" == "remove" ]]; then
log_verbose "Running: stow -d ${DOTFILES_DIR} -t ${HOME} -D ${package}"
stow -d "${DOTFILES_DIR}" -t "${HOME}" -D "${package}" 2>/dev/null && \
print_success "Removed ${package}" || \
print_info "Package ${package} was not stowed"
else
# Remove foreign symlinks that would conflict with stow (files and directories)
while IFS= read -r rel_path; do
local target="${HOME}/${rel_path}"
if [[ -L "${target}" ]] && [[ "$(readlink "${target}")" != *"${DOTFILES_DIR}/${package}/"* ]]; then
rm "${target}"
print_info "Removed conflicting symlink: ${rel_path}"
fi
done < <(cd "${DOTFILES_DIR}/${package}" && find . \( -type f -o -type d \) ! -name . -printf '%P\n')
# Use --adopt to handle existing files, then restore from git
log_verbose "Running: stow -d ${DOTFILES_DIR} -t ${HOME} --restow --adopt ${package}"
if stow -d "${DOTFILES_DIR}" -t "${HOME}" --restow --adopt "${package}" 2>/dev/null; then
# Restore any adopted files to our version
log_verbose "Restoring adopted files from git"
git -C "${SCRIPT_DIR}" checkout -- "${DOTFILES_DIR}/${package}" 2>/dev/null || true
print_success "Installed ${package}"
else
print_error "Failed to install ${package}"
return 1
fi
fi
}
list_packages() {
echo "Available packages:"
for pkg in "${PACKAGES_ALL[@]}"; do
if [[ -d "${DOTFILES_DIR}/${pkg}" ]]; then
local marker=""
# Mark minimal packages
for min_pkg in "${PACKAGES_MINIMAL[@]}"; do
if [[ "$pkg" == "$min_pkg" ]]; then
marker=" (minimal)"
break
fi
done
echo " - ${pkg}${marker}"
fi
done
echo
echo "Profiles:"
echo " --minimal : ${PACKAGES_MINIMAL[*]}"
echo " --full : ${PACKAGES_ALL[*]}"
}
main() {
local action="install"
local skip_omz=false
local selected_packages=()
local profile=""
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help)
usage
exit 0
;;
-l|--list)
list_packages
exit 0
;;
-a|--all|--full)
profile="full"
shift
;;
--minimal)
profile="minimal"
shift
;;
-r|--remove)
action="remove"
shift
;;
-n|--no-omz)
skip_omz=true
shift
;;
-v|--verbose)
VERBOSE=true
shift
;;
--shellcheck)
shopt -s globstar
shellcheck -x -- "${SCRIPT_DIR}"/**/*.sh
exit $?
;;
-*)
print_error "Unknown option: $1"
usage
exit 1
;;
*)
selected_packages+=("$1")
shift
;;
esac
done
# Apply profile if set and no specific packages selected
if [[ ${#selected_packages[@]} -eq 0 ]]; then
case "$profile" in
minimal)
selected_packages=("${PACKAGES_MINIMAL[@]}")
;;
full|"")
selected_packages=("${PACKAGES_ALL[@]}")
;;
esac
fi
log_verbose "SCRIPT_DIR: ${SCRIPT_DIR}"
log_verbose "DOTFILES_DIR: ${DOTFILES_DIR}"
log_verbose "Action: ${action}"
log_verbose "Skip OMZ: ${skip_omz}"
log_verbose "Packages: ${selected_packages[*]}"
check_stow
if [[ "${action}" == "install" ]]; then
install_make
install_node
fi
echo "Dotfiles ${action}ation"
echo "========================"
for package in "${selected_packages[@]}"; do
log_verbose "Processing package: ${package}"
stow_package "${package}" "${action}"
done
# Install oh-my-zsh and fzf if installing zsh package
if [[ "${action}" == "install" ]] && [[ "${skip_omz}" == false ]]; then
for pkg in "${selected_packages[@]}"; do
if [[ "${pkg}" == "zsh" ]]; then
install_omz
install_fzf
break
fi
done
fi
# Install zsh companion tools (fd, bat, eza, lazygit)
if [[ "${action}" == "install" ]]; then
for pkg in "${selected_packages[@]}"; do
if [[ "${pkg}" == "zsh" ]]; then
install_fd
install_bat
install_eza
install_lazygit
install_yq
break
fi
done
fi
# Install tmux and TPM if installing tmux package
if [[ "${action}" == "install" ]]; then
for pkg in "${selected_packages[@]}"; do
if [[ "${pkg}" == "tmux" ]]; then
install_tmux
install_tpm
break
fi
done
fi
# Install ripgrep if installing ripgrep package
if [[ "${action}" == "install" ]]; then
for pkg in "${selected_packages[@]}"; do
if [[ "${pkg}" == "ripgrep" ]]; then
install_ripgrep
break
fi
done
fi
# Install latest Neovim if installing nvim package
if [[ "${action}" == "install" ]]; then
for pkg in "${selected_packages[@]}"; do
if [[ "${pkg}" == "nvim" ]]; then
install_nvim
break
fi
done
fi
# Install GitHub CLI if installing gh package
if [[ "${action}" == "install" ]]; then
for pkg in "${selected_packages[@]}"; do
if [[ "${pkg}" == "gh" ]]; then
install_gh
break
fi
done
fi
echo
print_success "Done!"
}
main "$@"