-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
526 lines (443 loc) · 14.7 KB
/
Copy pathinstall.sh
File metadata and controls
526 lines (443 loc) · 14.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
#!/bin/bash
# 定义变量
DOTFILES_DIR="$HOME/dotfiles"
CONFIG_DIR="$HOME/.config"
source "$DOTFILES_DIR/local/index.zsh"
command_exists() {
command -v "$1" >/dev/null 2>&1
}
link_dir() {
local src="$DOTFILES_DIR/$1"
local dest="$CONFIG_DIR/$1"
[ -d "$dest" ] && [ ! -L "$dest" ] && rm -rf "$dest"
ln -sfn "$src" "$dest"
}
setup_espanso() {
local target="$HOME/Library/Application Support/espanso"
[ -d "$target" ] && [ ! -L "$target" ] && rm -rf "$target"
ln -sfn "$DOTFILES_DIR/espanso" "$target"
command_exists espanso || return
if ! espanso status 2>/dev/null | grep -q running; then
echo "🚀 启动 espanso 服务..."
espanso service register || true
espanso start || echo "⚠ espanso 启动失败,请运行 'espanso log' 查看原因"
else
espanso restart >/dev/null 2>&1 || true
echo "✓ espanso 已重载配置"
fi
}
link_git_scripts() {
echo "🔗 正在链接 git 脚本..."
local git_scripts_dir="$DOTFILES_DIR/git"
local bin_dir="$HOME/.local/bin"
mkdir -p "$bin_dir"
for script in "$git_scripts_dir"/git-*; do
if [ -f "$script" ]; then
local script_name=$(basename "$script")
local subcmd=${script_name#git-}
if git --list-cmds=main,alias | grep -q "^$subcmd$"; then
echo " ⚠️ Git 子命令 '$subcmd' 已存在(内置或别名),跳过链接 $script_name"
continue
fi
ln -sf "$script" "$bin_dir/$script_name"
chmod +x "$script"
echo " ✓ Linked $script_name"
fi
done
}
install_if_missing() {
local cmd="$1"
local package="${2:-$1}"
if command_exists "$cmd"; then
echo "✓ $cmd 已安装"
else
echo "⚠ $cmd 未找到,正在安装 $package..."
if [ "$package" = "im-select" ]; then
install_tap_if_missing "daipeihust/tap"
fi
brew install "$package"
if [ "$cmd" = "opencode" ]; then
echo "📦 安装 oh-my-opencode..."
(cd "$CONFIG_DIR/opencode" && bun i oh-my-opencode@3.0.0-beta.6)
echo "✓ oh-my-opencode 安装完成"
fi
if [ "$package" = "tealdeer" ]; then
tldr --update
fi
if [ "$package" = "git-lfs" ]; then
git lfs install
fi
fi
}
install_yazi_plugins() {
local yazi_plugins_dir="$CONFIG_DIR/yazi/plugins"
mkdir -p "$yazi_plugins_dir"
local plugins=(
"yazi-rs/plugins:full-border"
"yazi-rs/plugins:smart-enter"
"yazi-rs/plugins:chmod"
)
for plugin in "${plugins[@]}"; do
local plugin_name="${plugin##*:}"
local plugin_dir="$yazi_plugins_dir/${plugin_name}.yazi"
if [ -d "$plugin_dir" ]; then
echo "✓ yazi 插件 $plugin_name 已安装"
else
echo "📦 安装 yazi 插件 $plugin_name..."
# 防止目录不存在但package.toml中仍有记录
ya pkg delete "$plugin" 2>/dev/null || true
ya pkg add "$plugin"
fi
done
ln -sfn "$DOTFILES_DIR/yazi/plugins/smart-rename.yazi" "$CONFIG_DIR/yazi/plugins/smart-rename.yazi"
}
install_zinit_if_missing() {
local zinit_home="${XDG_DATA_HOME:-$HOME/.local/share}/zinit/zinit.git"
if [ -f "$zinit_home/zinit.zsh" ]; then
echo "✓ zinit 已安装"
else
echo "📦 安装 zinit..."
mkdir -p "$(dirname "$zinit_home")"
git clone https://github.com/zdharma-continuum/zinit.git "$zinit_home"
echo "✓ zinit 安装完成"
fi
}
install_zinit_plugins() {
echo "📦 安装 zinit 插件..."
zsh -i -c "@zinit-scheduler burst" 2>/dev/null || true
echo "✓ zinit 插件安装完成"
}
install_brew_if_missing() {
if command_exists "brew"; then
echo "✓ Homebrew 已安装"
else
echo "⚠ Homebrew 未找到,正在安装..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
}
install_tap_if_missing() {
local tap_name="$1"
if brew tap | grep -qx "$tap_name"; then
echo "✓ tap $tap_name 已存在"
else
echo "📦 添加 Homebrew tap: $tap_name"
brew tap "$tap_name"
fi
}
# 将 dotfiles/homebrew 链接为 local/tap,用于锁定特定版本的 formula
setup_local_tap() {
local tap_dir
tap_dir="$(brew --repository)/Library/Taps/local"
local target="$tap_dir/homebrew-tap"
if [ -L "$target" ] && [ "$(readlink "$target")" = "$DOTFILES_DIR/homebrew" ]; then
echo "✓ local/tap 已链接到 dotfiles/homebrew"
else
echo "🔗 链接 dotfiles/homebrew -> local/tap..."
mkdir -p "$tap_dir"
rm -rf "$target"
ln -sfn "$DOTFILES_DIR/homebrew" "$target"
echo "✓ local/tap 链接完成"
fi
}
install_rust_if_missing() {
if command_exists "rustc"; then
echo "✓ Rust 已安装"
else
echo "⚠ Rust 未找到,正在安装..."
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
fi
}
install_pip3_if_missing() {
if command_exists "pip3"; then
echo "✓ pip3 已安装"
else
echo "⚠ pip3 未找到,正在通过 Homebrew 安装 Python..."
brew install python
fi
}
install_pipx_package_if_missing() {
local cmd="$1"
local package="${2:-$1}"
if command_exists "$cmd"; then
echo "✓ $cmd 已安装"
else
echo "⚠ $cmd 未找到,正在通过 pipx 安装 $package..."
pipx install "$package"
fi
}
install_nvm_if_missing() {
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
if command_exists "nvm"; then
echo "✓ nvm 已安装"
else
echo "⚠ nvm 未找到,正在安装..."
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
fi
}
install_tode_if_missing() {
if command_exists "tode"; then
echo "✓ tode 已安装"
else
echo "⚠ tode 未找到,正在安装..."
curl -fsSL https://tode.sh/install | bash
fi
}
install_npm_if_missing() {
local cmd="$1"
local package="${2:-$1}"
if command_exists "$cmd"; then
echo "✓ $cmd 已安装"
else
echo "⚠ $cmd 未找到,正在安装 $package..."
npm i -g "$package"
fi
}
setup_kitty_icon() {
kitty +runpy 'exec(__import__("textwrap").dedent("""
from kitty.fast_data_types import cocoa_set_app_icon
import sys
cocoa_set_app_icon(*sys.argv[1:])
print("OK")
"""))' "$DOTFILES_DIR/kitty/kitty-alternative.icns"
rm -rf /var/folders/*/*/*/com.apple.dock.iconcache 2>/dev/null || true
killall Dock
echo "✓ Dock 图标已刷新"
}
install_cask_if_missing() {
local cask_name="$1"
if brew list --cask "$cask_name" &>/dev/null; then
echo "✓ $cask_name 已安装"
else
echo "⚠ $cask_name 未找到,正在安装..."
brew install --cask "$cask_name"
fi
}
install_app_if_missing() {
local app_name="$1"
local cask_name="$2"
local app_path="${3:-/Applications/$app_name.app}"
if [ -d "$app_path" ]; then
echo "✓ $app_name 已安装"
else
echo "⚠ $app_name 未找到,正在安装..."
if [ "$cask_name" = "keystats" ]; then
install_tap_if_missing "debugtheworldbot/keystats"
fi
brew install --cask "$cask_name"
fi
}
install_font_if_missing() {
local font_file="$1"
local font_name="${font_file%.ttf}"
if [ -f "$HOME/Library/Fonts/$font_file" ]; then
echo "✓ $font_name 字体已安装"
else
echo "⚠ $font_name 字体未找到,正在安装..."
cp "$DOTFILES_DIR/fonts/$font_file" "$HOME/Library/Fonts/"
fi
}
clone_apps_repo() {
local apps_dir="$HOME/apps"
if [ -d "$apps_dir" ]; then
echo "✓ apps 仓库已存在"
else
echo "📦 克隆 apps 仓库..."
git clone https://github.com/xiaoliyooo/apps "$apps_dir"
echo "✓ apps 仓库克隆完成"
fi
}
install_from_dmg() {
local dmg_path="$1"
local filename=$(basename "$dmg_path")
# 文件名格式: 软件名_版本.dmg
local app_name="${filename%%_*}"
if [ -d "/Applications/$app_name.app" ]; then
echo "✓ $app_name 已安装"
return 0
fi
echo "⚠ 正在从 dmg 安装 $app_name..."
local mount_output=$(yes | hdiutil attach "$dmg_path" -nobrowse -noautoopen -noverify 2>/dev/null)
local mount_point=$(echo "$mount_output" | grep "/Volumes" | sed 's/.*\(\/Volumes\/.*\)/\1/' | head -1)
if [ -z "$mount_point" ]; then
echo "✗ 无法挂载 $dmg_path"
return 1
fi
if ls "$mount_point"/*.app 1>/dev/null 2>&1; then
cp -Rf "$mount_point"/*.app /Applications/
echo "✓ $app_name 安装完成"
else
echo "⚠ $mount_point 中未找到 .app 文件"
fi
}
scan_and_install_dmgs() {
local dir="$1"
if [ ! -d "$dir" ]; then
echo "⚠ 目录不存在: $dir"
return 1
fi
for item in "$dir"/*; do
if [ -d "$item" ]; then
scan_and_install_dmgs "$item"
elif [ -f "$item" ] && [[ "$item" == *.dmg ]]; then
install_from_dmg "$item"
fi
done
}
echo "🚀 开始安装 dotfiles..."
# 禁用系统默认英文 "Last login:" 消息
[[ ! -e "$HOME/.hushlogin" ]] && touch "$HOME/.hushlogin"
ln -sf "$DOTFILES_DIR/bun/.bunfig.toml" "$HOME/.bunfig.toml"
install_brew_if_missing
setup_local_tap
install_rust_if_missing
install_nvm_if_missing
install_tode_if_missing
install_pip3_if_missing
install_zinit_if_missing
install_zinit_plugins
install_font_if_missing "JetBrainsMonoNL-Bold.ttf"
install_cask_if_missing "font-fira-code"
install_cask_if_missing "font-fira-code-nerd-font"
install_cask_if_missing "hammerspoon"
install_npm_if_missing "tsc" "typescript"
install_npm_if_missing "bun"
install_if_missing "pipx"
install_if_missing "kitty"
install_if_missing "prettier"
install_if_missing "pnpm"
install_if_missing "git"
install_if_missing "bat"
install_if_missing "delta"
install_if_missing "eza"
install_if_missing "tree"
install_if_missing "nvim" "local/tap/neovim"
install_if_missing "nvimpager"
install_if_missing "gdate" "coreutils"
install_if_missing "mergiraf"
install_if_missing "starship"
install_if_missing "lazygit"
install_if_missing "nvr" "neovim-remote"
install_if_missing "less"
install_if_missing "zoxide"
install_if_missing "yazi"
install_if_missing "7zz" "sevenzip"
install_if_missing "fzf"
install_if_missing "fd"
install_if_missing "tokei"
install_if_missing "mprocs"
install_if_missing "git-summary" "git-extras"
install_if_missing "git-absorb"
install_if_missing "difft" "difftastic"
install_if_missing "git-lfs"
install_if_missing "git-imerge"
install_if_missing "gemini" "gemini-cli"
install_if_missing "opencode" "anomalyco/tap/opencode"
install_if_missing "im-select"
install_if_missing "ttyd"
install_if_missing "ni"
install_if_missing "killport"
install_if_missing "onefetch"
install_if_missing "atuin"
install_if_missing "tldr" "tealdeer"
install_if_missing "vivid"
install_if_missing "carapace"
install_if_missing "btop"
install_if_missing "dust"
install_if_missing "magick" "imagemagick"
install_if_missing "rg" "ripgrep"
install_if_missing "rust-analyzer"
install_if_missing "has"
install_if_missing "pstree"
install_if_missing "mackup"
install_pipx_package_if_missing "starcli"
# ━━━━━━━━━━━━━━━━━━━━ neovim formatter/linter start ━━━━━━━━━━━━━━━━━━
install_if_missing "stylua"
install_if_missing "shfmt"
install_if_missing "shellcheck"
install_if_missing "taplo"
install_if_missing "ruff"
install_if_missing "sql-formatter"
# ━━━━━━━━━━━━━━━━━━━━━ neovim formatter/linter end ━━━━━━━━━━━━━━━━━━━
install_app_if_missing "WeChat" "wechat"
install_app_if_missing "微信输入法" "wetype" "$HOME/Library/Input Methods/WeType.app"
install_app_if_missing "QQMusic" "qqmusic"
install_app_if_missing "NeteaseMusic" "neteasemusic"
install_app_if_missing "Google Chrome" "google-chrome"
install_app_if_missing "Obsidian" "obsidian"
install_app_if_missing "Karabiner-Elements" "karabiner-elements"
install_app_if_missing "Docker" "docker"
install_app_if_missing "wpsoffice" "wpsoffice"
install_app_if_missing "Clash Verge" "clash-verge-rev"
install_app_if_missing "SwitchHosts" "switchhosts"
install_app_if_missing "Ice" "jordanbaird-ice"
install_app_if_missing "Tencent Lemon" "tencent-lemon"
# install_app_if_missing "Visual Studio Code" "visual-studio-code"
# install_app_if_missing "Antigravity" "antigravity"
install_app_if_missing "AltTab" "alt-tab"
install_app_if_missing "KeyStats" "keystats"
install_app_if_missing "Doubao" "doubao"
install_app_if_missing "Homerow" "homerow"
install_app_if_missing "Espanso" "espanso"
clone_apps_repo
scan_and_install_dmgs "$HOME/apps/app-dmg"
mkdir -p "$CONFIG_DIR/lazygit"
mkdir -p "$CONFIG_DIR/git"
mkdir -p "$CONFIG_DIR/yazi"
mkdir -p "$CONFIG_DIR/opencode"
mkdir -p "$CONFIG_DIR/atuin"
mkdir -p "$CONFIG_DIR/btop"
ln -sf "$DOTFILES_DIR/git/gitconfig" "$HOME/.gitconfig"
rm -rf "$HOME/.vimrc" "$HOME/.tmux.conf"
ln -sf "$DOTFILES_DIR/vim/.vimrc" "$HOME/.vimrc"
ln -sf "$DOTFILES_DIR/tmux/.tmux.conf" "$HOME/.tmux.conf"
[ -d "$HOME/.hammerspoon" ] && [ ! -L "$HOME/.hammerspoon" ] && rm -rf "$HOME/.hammerspoon"
ln -sfn "$DOTFILES_DIR/hammerspoon" "$HOME/.hammerspoon"
ln -sf "$DOTFILES_DIR/lazygit/lazygit_config.yml" "$CONFIG_DIR/lazygit/config.yml"
ln -sf "$DOTFILES_DIR/git/attributes" "$CONFIG_DIR/git/attributes"
ln -sf "$DOTFILES_DIR/starship/starship.toml" "$CONFIG_DIR/starship.toml"
ln -sf "$DOTFILES_DIR/less/.lesskey" "$HOME/.lesskey"
ln -sf "$DOTFILES_DIR/yazi/keymap.toml" "$CONFIG_DIR/yazi/keymap.toml"
ln -sf "$DOTFILES_DIR/yazi/theme.toml" "$CONFIG_DIR/yazi/theme.toml"
ln -sf "$DOTFILES_DIR/yazi/yazi.toml" "$CONFIG_DIR/yazi/yazi.toml"
ln -sf "$DOTFILES_DIR/yazi/init.lua" "$CONFIG_DIR/yazi/init.lua"
ln -sf "$DOTFILES_DIR/atuin/config.toml" "$CONFIG_DIR/atuin/config.toml"
# atuin daemon被懒加载导致atuin的autostart没有效果,手动配置开机自启atuin daemon
ln -sf "$DOTFILES_DIR/atuin/com.atuin.daemon.plist" "$HOME/Library/LaunchAgents/com.atuin.daemon.plist"
launchctl load "$HOME/Library/LaunchAgents/com.atuin.daemon.plist" 2>/dev/null
setup_local
link_dir "kitty"
setup_kitty_icon
link_dir "tealdeer"
link_dir "mprocs"
link_dir "bat"
link_dir "btop"
link_dir "karabiner"
setup_espanso
echo "🔗 配置 nvimpager..."
ln -sfn "$CONFIG_DIR/nvim" "$CONFIG_DIR/nvimpager"
mkdir -p "$HOME/.local/share"
ln -sfn "$HOME/.local/share/nvim" "$HOME/.local/share/nvimpager"
link_git_scripts
echo "🔗 配置文件链接完成..."
install_yazi_plugins
# mackup
ln -sf "$DOTFILES_DIR/.mackup.cfg" "$HOME/.mackup.cfg"
[ -d "$HOME/.mackup" ] && [ ! -L "$HOME/.mackup" ] && rm -rf "$HOME/.mackup"
ln -sfn "$DOTFILES_DIR/mackup/applications" "$HOME/.mackup"
source "$DOTFILES_DIR/macos/defaults.sh"
# 重载 zsh 和 kitty 配置
echo "🔄 重载配置..."
zsh -ic 'source ~/.zshrc && reload -a' 2>/dev/null || true
if pgrep -f kitty.app >/dev/null 2>&1; then
for sock in /tmp/locator_vim_kitty--*; do
kitty @ --to "unix:$sock" load-config 2>/dev/null || true
done
echo "✓ kitty 配置已重载"
fi
echo "✓ zsh 配置已重载"
echo "✅ 安装完成!"
echo ""
echo "💡 如需同步Map应用配置(Moom、AltTab 等),请手动执行:"
echo " sh ./app-restore.sh"
echo " Bob配置文件在apps中~"