-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-machine
More file actions
executable file
·182 lines (160 loc) · 3.72 KB
/
setup-machine
File metadata and controls
executable file
·182 lines (160 loc) · 3.72 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
#!/usr/bin/env bash
set -euo pipefail
# ─────────
# Help Text
# ─────────
show_help() {
cat << EOF
Usage: $(basename "$0") [OPTIONS]
Options:
-d, --dir DIR Directory containing dotfiles (default: ~/dotfiles)
-n, --dry-run Print the actions without executing them
-f, --force Force overwrite existing directories by deleting them, by default directories are not overwritten
--no-confirm Avoid asking for confirmation while deleting directories (used with -f, --force)
--with-hypr Include Hyprland config linking
-h, --help Show this help message
This script links dotfiles to appropriate places(overwrites the files).
EOF
}
# ────────
# Defaults
# ────────
default_dir="${HOME}/dotfiles"
target_dir="$default_dir"
dry_run=false
force=false
no_confirm=false
with_hypr=false
# ───────────────
# Parse Arguments
# ───────────────
while [[ $# -gt 0 ]]; do
case "$1" in
-d|--dir)
next_arg="${2-}"
if [[ -z "$next_arg" || "$next_arg" == -* ]]; then
echo "Error: --dir requires a non-empty argument."
show_help
exit 1
fi
target_dir="$next_arg"
shift 2
;;
-n|--dry-run)
dry_run=true
shift
;;
-f|--force)
force=true
shift
;;
--no-confirm)
no_confirm=true
shift
;;
--with-hypr)
with_hypr=true
shift
;;
-h|--help)
show_help
exit 0
;;
*)
echo "Unknown option: $1"
show_help
exit 1
;;
esac
done
if $no_confirm && ! $force; then
echo "Error: --no-confirm requires --force argument to be set"
show_help
exit 1
fi
# ─────
# Setup
# ─────
echo "🔧 Using target dotfiles directory: $target_dir"
# Ensure TPM is installed
if [[ "$dry_run" == false ]]; then
if [[ ! -d "$HOME/.tmux/plugins/tpm" ]]; then
echo "📦 Cloning TPM..."
git clone https://github.com/tmux-plugins/tpm "$HOME/.tmux/plugins/tpm"
fi
fi
# Detect OS and set ln options accordingly
case "$(uname)" in
Darwin)
ln_opts="-svfF"
;;
Linux)
ln_opts="-svfT"
;;
*)
echo "❌ Unsupported OS: $(uname)"
exit 1
;;
esac
# ─────────────
# Link Function
# ─────────────
link() {
local src="$1"
local dest="$2"
if $dry_run; then
echo "[dry-run] Would link: $src → $dest"
return
fi
if [[ -e "$dest" && ! -L "$dest" ]]; then
if $force; then
if ! $no_confirm; then
read -rp "⚠️ Remove existing target $dest? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || {
echo "⏭️ Skipping: $dest (user declined)"
return
}
fi
echo "🗑 Removing: $dest"
rm -r "$dest"
else
echo "⏭️ Skipping (exists, use --force): $dest"
return
fi
fi
ln $ln_opts "$src" "$dest"
}
# ─────────────
# Files to Link
# ─────────────
base_files=(
".zexports"
".zprofile"
".zau"
".zshrc"
)
config_files=(
"nvim"
"tmux"
"wezterm"
)
if [[ "$with_hypr" == true ]]; then
config_files+=("hypr")
fi
# ─────────────
# Link Dotfiles
# ─────────────
echo "📁 Linking base files to ~"
pushd "$HOME" > /dev/null
for file in "${base_files[@]}"; do
link "$target_dir/$file" "$HOME/$file"
done
echo "📁 Linking .config files"
mkdir -p "$HOME/.config"
pushd "$HOME/.config" > /dev/null
for cfg in "${config_files[@]}"; do
link "$target_dir/$cfg" "$HOME/.config/$cfg"
done
popd > /dev/null
popd > /dev/null
echo "✅ Linking complete!"