-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdot
More file actions
executable file
·408 lines (353 loc) · 11.7 KB
/
Copy pathdot
File metadata and controls
executable file
·408 lines (353 loc) · 11.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
#!/usr/bin/env bash
set -euo pipefail
readonly RED='\033[0;31m'
readonly GREEN='\033[0;32m'
readonly BLUE='\033[0;34m'
readonly CYAN='\033[0;36m'
readonly RESET='\033[0m'
readonly BOLD='\033[1m'
readonly SCRIPT_NAME="dot"
readonly VERSION="1.0.0"
SCRIPT_PATH="${BASH_SOURCE[0]}"
while [[ -L "$SCRIPT_PATH" ]]; do
SCRIPT_PATH="$(readlink "$SCRIPT_PATH")"
done
DOTFILES_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
readonly DOTFILES_DIR
readonly PACKAGES_DIR="${DOTFILES_DIR}/packages"
readonly HOME_DIR="${DOTFILES_DIR}/home"
print_header() { echo -e "\n${BOLD}${BLUE}==>${RESET} ${BOLD}$1${RESET}"; }
print_success() { echo -e "${GREEN}✓${RESET} $1"; }
print_error() { echo -e "${RED}✗${RESET} $1" >&2; }
print_info() { echo -e "${CYAN}ℹ${RESET} $1"; }
command_exists() { command -v "$1" >/dev/null 2>&1; }
eval_brew() {
if [[ "$(uname -m)" == "arm64" ]]; then
eval "$(/opt/homebrew/bin/brew shellenv)"
else
eval "$(/usr/local/bin/brew shellenv)"
fi
}
install_homebrew() {
print_header "Installing Homebrew"
if command_exists brew; then
print_success "Homebrew already installed"
return 0
fi
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
eval_brew
print_success "Homebrew installed"
}
install_packages() {
print_header "Installing packages from Brewfile"
if [[ ! -f "${PACKAGES_DIR}/Brewfile" ]]; then
print_error "Brewfile not found at ${PACKAGES_DIR}/Brewfile"
return 1
fi
brew bundle --file="${PACKAGES_DIR}/Brewfile"
print_success "Packages installed"
}
link_dot_cli() {
print_header "Linking dot CLI"
mkdir -p "${HOME}/.local/bin"
ln -sf "${DOTFILES_DIR}/dot" "${HOME}/.local/bin/dot"
print_success "dot linked to ~/.local/bin/dot"
}
stow_dotfiles() {
print_header "Stowing dotfiles"
if ! command_exists stow; then
print_error "GNU Stow not installed. Run: brew install stow"
return 1
fi
local old_symlinks=(
"$HOME/.config/nvim"
"$HOME/.config/ghostty"
"$HOME/.config/jj/config.toml"
"$HOME/.config/tmux/tmux.conf.local"
"$HOME/.config/tmux/tmux-cht-command"
"$HOME/.config/tmux/tmux-cht-languages"
"$HOME/.config/git/config"
"$HOME/.config/opencode/opencode.json"
"$HOME/.config/opencode/oh-my-opencode.json"
"$HOME/.config/opencode/oh-my-openagent.json"
"$HOME/.config/opencode/tui.json"
"$HOME/.config/opencode/command/rmslop.md"
"$HOME/.config/opencode/command/supermemory-init.md"
"$HOME/.config/opencode/themes/tokyonight-transparent.json"
"$HOME/.omo/omo.jsonc"
"$HOME/.config/starship.toml"
"$HOME/.local/bin/scripts"
"$HOME/.gitconfig"
"$HOME/.zshrc"
"$HOME/.zprofile"
"$HOME/.antigenrc"
"$HOME/.aerospace.toml"
"$HOME/.tmux-cht-command"
"$HOME/.tmux-cht-languages"
)
for link in "${old_symlinks[@]}"; do
[[ -L "$link" ]] && rm -f "$link"
done
local generated_files=(
"$HOME/.config/opencode/tui.json"
"$HOME/.omo/omo.jsonc"
)
for file in "${generated_files[@]}"; do
if [[ -e "$file" && ! -L "$file" ]]; then
local backup="${file}.backup-$(date +%Y%m%d%H%M%S)"
mv "$file" "$backup"
print_info "Backed up existing ${file#$HOME/} to ${backup#$HOME/}"
fi
done
stow -R -v -d "${DOTFILES_DIR}" -t "${HOME}" home
print_success "Dotfiles stowed"
}
link_tmux_submodule() {
print_header "Linking tmux submodule"
mkdir -p "${HOME}/.config/tmux"
ln -sf "${DOTFILES_DIR}/.tmux/.tmux.conf" "${HOME}/.config/tmux/tmux.conf"
print_success "tmux.conf linked"
}
ensure_zdotdir() {
print_header "Configuring ZDOTDIR"
local zshenv="$HOME/.zshenv"
if ! grep -q 'ZDOTDIR' "$zshenv" 2>/dev/null; then
if [[ -f "$zshenv" ]]; then
local tmp=$(mktemp)
echo 'export ZDOTDIR="$HOME/.config/zsh"' | cat - "$zshenv" > "$tmp"
mv "$tmp" "$zshenv"
else
echo 'export ZDOTDIR="$HOME/.config/zsh"' > "$zshenv"
fi
print_success "ZDOTDIR added to .zshenv"
else
print_success "ZDOTDIR already configured"
fi
}
install_fonts() {
print_header "Installing fonts"
local font_dir="${DOTFILES_DIR}/fonts"
if [[ -d "$font_dir" ]]; then
cp -R "$font_dir"/* "$HOME/Library/Fonts/"
print_success "Fonts installed"
else
print_info "No fonts directory found"
fi
}
generate_ssh_key() {
print_header "Generating SSH key"
local key_path="$HOME/.ssh/key"
if [[ -f "$key_path" ]]; then
print_success "SSH key already exists"
return 0
fi
mkdir -p "$HOME/.ssh"
chmod 700 "$HOME/.ssh"
read -r -p "Enter email for SSH key: " email
ssh-keygen -t ed25519 -C "$email" -f "$key_path"
print_success "SSH key generated"
print_info "Add to GitHub: pbcopy < ${key_path}.pub"
}
install_opencode() {
print_header "Installing OpenCode"
if command_exists opencode; then
print_success "OpenCode already installed"
return 0
fi
curl -fsSL https://opencode.ai/install | bash
print_success "OpenCode installed"
}
install_antigen() {
print_header "Installing Antigen"
if [[ -f "$HOME/antigen.zsh" ]]; then
print_success "Antigen already installed"
return 0
fi
curl -L git.io/antigen > "$HOME/antigen.zsh"
print_success "Antigen installed"
}
install_rust() {
print_header "Installing Rust"
if command_exists rustc; then
rustc -V
print_success "Rust already installed"
return 0
fi
rustup-init -y
print_success "Rust installed"
}
install_ocaml() {
print_header "Installing OCaml"
if ! command_exists opam; then
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://opam.ocaml.org/install.sh)"
opam init -y
fi
opam update -y
if opam switch list -s --all >/dev/null 2>&1; then
opam_switches=$(opam switch list -s --all 2>/dev/null)
else
opam_switches=$(opam switch list --short 2>/dev/null)
fi
if ! echo "$opam_switches" | grep -Fxq "5.4.0"; then
opam switch create 5.4.0 ocaml-base-compiler.5.4.0 -y
opam install -y ocaml-lsp-server odoc ocamlformat utop core core_bench
print_success "OCaml 5.4.0 installed"
else
print_success "OCaml 5.4.0 already installed"
fi
}
install_node() {
print_header "Installing Node.js"
if command_exists node; then
node -v
print_success "Node.js already installed"
return 0
fi
eval "$(fnm env --use-on-cd)"
fnm use 22 --install-if-missing
npm i -g pnpm @antfu/ni
print_success "Node.js installed"
}
install_bun() {
print_header "Installing Bun"
if command_exists bun; then
print_success "Bun already installed"
return 0
fi
curl -fsSL https://bun.sh/install | bash
print_success "Bun installed"
}
install_gh_extensions() {
print_header "Installing GitHub CLI extensions"
if ! command_exists gh; then
print_warning "gh not found, skipping extensions"
return 0
fi
gh extension install dlvhdr/gh-dash 2>/dev/null || true
print_success "gh extensions installed"
}
cmd_init() {
local skip_font=false
local skip_ssh=false
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-font) skip_font=true; shift ;;
--skip-ssh) skip_ssh=true; shift ;;
*) shift ;;
esac
done
print_header "Initializing dotfiles"
install_homebrew
eval_brew
install_packages
link_dot_cli
ensure_zdotdir
stow_dotfiles
link_tmux_submodule
[[ "$skip_font" == false ]] && install_fonts
[[ "$skip_ssh" == false ]] && generate_ssh_key
install_opencode
install_antigen
install_rust
install_ocaml
install_node
install_bun
install_gh_extensions
print_header "Initialization complete! 🎉"
print_info "Open a new terminal to apply changes"
}
cmd_update() {
print_header "Updating dotfiles"
if [[ -d "${DOTFILES_DIR}/.jj" ]] && command_exists jj; then
print_info "Updating via jj"
jj git fetch -R "$DOTFILES_DIR"
jj -R "$DOTFILES_DIR" rebase -d 'trunk()'
else
git -C "$DOTFILES_DIR" pull
fi
print_success "Repository updated"
print_info "Updating Homebrew packages"
brew update && brew upgrade
print_success "Packages updated"
stow_dotfiles
link_tmux_submodule
}
cmd_doctor() {
print_header "Running diagnostics"
local issues=0
command_exists brew && print_success "Homebrew" || { print_error "Homebrew not found"; ((++issues)); }
command_exists stow && print_success "GNU Stow" || { print_error "Stow not found"; ((++issues)); }
command_exists git && print_success "Git" || { print_error "Git not found"; ((++issues)); }
command_exists nvim && print_success "Neovim" || { print_error "Neovim not found"; ((++issues)); }
command_exists tmux && print_success "Tmux" || { print_error "Tmux not found"; ((++issues)); }
command_exists node && print_success "Node.js" || print_info "Node.js not found"
command_exists bun && print_success "Bun" || print_info "Bun not found"
command_exists rustc && print_success "Rust" || print_info "Rust not found"
command_exists opencode && print_success "OpenCode" || print_info "OpenCode not found"
[[ -f "$HOME/.ssh/key" ]] && print_success "SSH key exists" || print_info "No SSH key"
grep -q 'ZDOTDIR' "$HOME/.zshenv" 2>/dev/null && print_success "ZDOTDIR configured" || print_error "ZDOTDIR not set in .zshenv"
if [[ $issues -eq 0 ]]; then
print_header "All checks passed! ✨"
else
print_header "Found $issues issues"
fi
}
cmd_stow() {
stow_dotfiles
link_tmux_submodule
ensure_zdotdir
}
cmd_brew() {
print_header "Installing from Brewfile"
install_packages
}
cmd_edit() {
${EDITOR:-nvim} "$DOTFILES_DIR"
}
cmd_skills() {
print_header "Syncing agent skills"
local src="$HOME/.agents"
local dest="$DOTFILES_DIR/home/.agents"
if [[ ! -d "$src/skills" ]]; then
print_error "No skills found at $src/skills"
return 1
fi
rm -rf "$dest/skills"
mkdir -p "$dest/skills"
cp -r "$src/skills/"* "$dest/skills/"
[[ -f "$src/.skill-lock.json" ]] && cp "$src/.skill-lock.json" "$dest/.skill-lock.json"
print_success "Skills synced to dotfiles"
print_info "Run 'dot stow' if needed"
}
cmd_help() {
cat << EOF
${BOLD}dot${RESET} - dotfiles management CLI (v${VERSION})
${BOLD}USAGE:${RESET}
dot <command> [options]
${BOLD}COMMANDS:${RESET}
init [--skip-font] [--skip-ssh] Full setup
update Pull + brew upgrade + restow
doctor Run health checks
stow Re-symlink dotfiles
brew Install from Brewfile
edit Open dotfiles in editor
skills Sync agent skills to dotfiles
help Show this help
${BOLD}EXAMPLES:${RESET}
dot init # Full installation
dot init --skip-font --skip-ssh # Skip optional steps
dot update # Update everything
dot stow # Re-create symlinks
EOF
}
case "${1:-help}" in
init) shift; cmd_init "$@" ;;
update) cmd_update ;;
doctor) cmd_doctor ;;
stow) cmd_stow ;;
brew) cmd_brew ;;
edit) cmd_edit ;;
skills) cmd_skills ;;
help|--help|-h) cmd_help ;;
*) print_error "Unknown command: $1"; cmd_help; exit 1 ;;
esac