forked from typhoon1217/ubuntuserverinit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-macos-x86.sh
More file actions
executable file
·956 lines (792 loc) · 26.7 KB
/
install-macos-x86.sh
File metadata and controls
executable file
·956 lines (792 loc) · 26.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
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
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
#!/usr/bin/env bash
################################################################################
# macOS (Intel/x86_64) Server Initial Setup Script
#
# Description: Interactive installation script for essential development tools
# Author: Generated for choovin
# Date: 2025-02-03
#
# Features:
# - Interactive Y/N prompts for each component
# - Robust error handling with colored output
# - Comprehensive logging
# - Zsh with prefix-based history search
# - Latest stable versions from Homebrew
################################################################################
set -euo pipefail
################################################################################
# Global Variables
################################################################################
AUTO_YES=false
ARCH_TYPE="x86_64"
LOG_FILE="$HOME/macos-setup-$(date +%Y%m%d-%H%M%S).log"
BACKUP_DIR="$HOME/.config-backups/$(date +%Y%m%d-%H%M%S)"
HOMEBREW_PREFIX="/usr/local"
# China mirror flags (detected automatically)
IS_CHINA=false
GITHUB_PROXY=""
# Mirror URLs for China
HOMEBREW_BREW_GIT="https://github.com/Homebrew/brew"
HOMEBREW_CORE_GIT="https://github.com/Homebrew/homebrew-core"
HOMEBREW_BOTTLE_DOMAIN="https://ghcr.io/v2/homebrew/core"
NPM_REGISTRY="https://registry.npmjs.org"
PIP_INDEX_URL="https://pypi.org/simple"
BUN_INSTALL_URL="https://bun.sh/install"
################################################################################
# Color Definitions & Logging Functions
################################################################################
if [ -t 1 ]; then
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
else
RED=''
GREEN=''
YELLOW=''
BLUE=''
CYAN=''
NC=''
fi
log_info() {
echo -e "${BLUE}[INFO]${NC} $1" | tee -a "$LOG_FILE"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOG_FILE"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1" | tee -a "$LOG_FILE"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOG_FILE"
}
log_header() {
echo -e "\n${CYAN}========================================${NC}" | tee -a "$LOG_FILE"
echo -e "${CYAN}$1${NC}" | tee -a "$LOG_FILE"
echo -e "${CYAN}========================================${NC}\n" | tee -a "$LOG_FILE"
}
################################################################################
# Helper Functions
################################################################################
ask_yn() {
local prompt="$1"
local default="${2:-y}"
local answer
if [ "$AUTO_YES" = true ]; then
echo -e "${CYAN}${prompt} [AUTO-YES]${NC}" | tee -a "$LOG_FILE"
return 0
fi
if [[ "$default" == "y" ]]; then
prompt="${prompt} [Y/n]: "
else
prompt="${prompt} [y/N]: "
fi
read -rp "$(echo -e "${CYAN}${prompt}${NC}")" answer
answer="${answer:-$default}"
[[ "$answer" =~ ^[Yy]$ ]]
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
backup_path() {
local path="$1"
if [ -e "$path" ]; then
mkdir -p "$BACKUP_DIR"
local backup_name
backup_name="$(basename "$path")-$(date +%H%M%S)"
cp -r "$path" "$BACKUP_DIR/$backup_name"
log_info "Backed up $path to $BACKUP_DIR/$backup_name"
fi
}
detect_china_network() {
log_header "Network Region Detection"
log_info "Detecting network region..."
# Method 1: Check IP location via ip-api.com
local country=""
if command_exists curl; then
country=$(curl -fsSL --connect-timeout 5 "http://ip-api.com/line/?fields=countryCode" 2>/dev/null || echo "")
fi
# Method 2: Fallback to ipinfo.io
if [ -z "$country" ] && command_exists curl; then
country=$(curl -fsSL --connect-timeout 5 "https://ipinfo.io/country" 2>/dev/null || echo "")
fi
# Method 3: Check if can access google.com (behind GFW)
if [ -z "$country" ]; then
if curl -fsSL --connect-timeout 3 "https://www.google.com" >/dev/null 2>&1; then
country="US"
else
country="CN"
fi
fi
if [ "$country" = "CN" ]; then
IS_CHINA=true
GITHUB_PROXY="https://gh-proxy.com/"
log_info "Detected China mainland network - using domestic mirrors"
# Set China mirror URLs
HOMEBREW_BREW_GIT="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
HOMEBREW_CORE_GIT="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
NPM_REGISTRY="https://registry.npmmirror.com"
PIP_INDEX_URL="https://mirrors.aliyun.com/pypi/simple"
BUN_INSTALL_URL="https://gh-proxy.com/https://github.com/oven-sh/bun/releases/latest/download/bun-darwin-x64.zip"
log_info "Mirrors configured:"
log_info " - Homebrew: TUNA (Tsinghua)"
log_info " - npm: npmmirror (Taobao)"
log_info " - pip: Aliyun"
log_info " - GitHub proxy: gh-proxy.com"
else
log_info "Detected non-China network: ${country:-Unknown}"
log_info "Using default international sources"
fi
log_success "Network region detection completed"
}
configure_china_mirrors() {
if [ "$IS_CHINA" = true ]; then
log_info "Configuring China mirrors..."
# Configure Homebrew mirrors
if command_exists brew; then
export HOMEBREW_BREW_GIT="$HOMEBREW_BREW_GIT"
export HOMEBREW_CORE_GIT="$HOMEBREW_CORE_GIT"
export HOMEBREW_BOTTLE_DOMAIN="$HOMEBREW_BOTTLE_DOMAIN"
# Also add to shell config for persistence
if ! grep -q "HOMEBREW_BREW_GIT" "$HOME/.zshrc" 2>/dev/null; then
cat >> "$HOME/.zshrc" << 'MIRROR_CONFIG'
# Homebrew China mirrors
export HOMEBREW_BREW_GIT="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git"
export HOMEBREW_CORE_GIT="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
export HOMEBREW_BOTTLE_DOMAIN="https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles"
MIRROR_CONFIG
fi
fi
# Configure npm mirror
if command_exists npm; then
npm config set registry "$NPM_REGISTRY"
log_info "npm registry set to: $NPM_REGISTRY"
fi
# Configure pip mirror
if command_exists pip || command_exists pip3; then
mkdir -p "$HOME/.pip"
cat > "$HOME/.pip/pip.conf" << 'PIP_CONFIG'
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
trusted-host = mirrors.aliyun.com
PIP_CONFIG
log_info "pip index set to: Aliyun mirror"
fi
log_success "China mirrors configured"
fi
}
check_homebrew() {
if ! command_exists brew; then
log_info "Homebrew not found. Installing Homebrew..."
# Use China mirror for Homebrew install script
local install_url="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
if [ "$IS_CHINA" = true ]; then
install_url="${GITHUB_PROXY}${install_url}"
fi
/bin/bash -c "$(curl -fsSL "$install_url")"
fi
if command_exists brew; then
# Configure Homebrew mirrors for China
if [ "$IS_CHINA" = true ]; then
export HOMEBREW_BREW_GIT="$HOMEBREW_BREW_GIT"
export HOMEBREW_CORE_GIT="$HOMEBREW_CORE_GIT"
export HOMEBREW_BOTTLE_DOMAIN="$HOMEBREW_BOTTLE_DOMAIN"
fi
log_success "Homebrew is installed: $(brew --version | head -n1)"
else
log_error "Failed to install Homebrew"
exit 1
fi
}
check_installation_status() {
log_header "Pre-Installation Status Check"
log_info "Checking what is currently installed..."
echo ""
local tools=("git" "zsh" "docker" "neovim" "node" "gcc" "tmux" "fzf" "rg" "fd" "btop" "lazygit" "lazydocker" "zoxide" "uv" "poetry" "luarocks" "bun" "ghostty" "claude")
for tool in "${tools[@]}"; do
if command_exists "$tool"; then
local version=$($tool --version 2>/dev/null | head -n1 || echo "installed")
echo -e " ${GREEN}✓${NC} $tool: $version" | tee -a "$LOG_FILE"
else
echo -e " ${RED}✗${NC} $tool: not installed" | tee -a "$LOG_FILE"
fi
done
echo ""
log_info "Status check complete"
}
check_prerequisites() {
log_header "Checking Prerequisites"
if ! command_exists curl; then
log_error "curl is required but not installed"
exit 1
fi
# Detect network region first for mirror configuration
detect_china_network
check_homebrew
# Configure mirrors after Homebrew is installed
configure_china_mirrors
if ! ping -c 1 baidu.com >/dev/null 2>&1; then
log_error "No internet connection detected"
exit 1
fi
log_success "Prerequisites check passed"
}
install_homebrew_formulae() {
local formulae=("$@")
for formula in "${formulae[@]}"; do
if brew list "$formula" >/dev/null 2>&1; then
log_info "$formula is already installed, upgrading..."
brew upgrade "$formula"
else
log_info "Installing $formula..."
brew install "$formula"
fi
done
}
install_git() {
log_header "Git Installation"
if command_exists git; then
log_warn "Git is already installed ($(git --version))"
if ! ask_yn "Reinstall/upgrade git?" "n"; then
return 1
fi
fi
if ask_yn "Install/upgrade git?" "y"; then
brew install git || brew upgrade git
log_success "Git installed: $(git --version)"
else
log_warn "Skipping git installation"
fi
}
install_zsh() {
log_header "Zsh & Oh-My-Zsh Installation"
if ask_yn "Install zsh with oh-my-zsh?" "y"; then
if ! command_exists zsh; then
log_info "Installing zsh..."
brew install zsh
fi
if [ ! -d "$HOME/.oh-my-zsh" ]; then
log_info "Installing oh-my-zsh..."
local ohmyzsh_url="https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh"
if [ "$IS_CHINA" = true ]; then
ohmyzsh_url="${GITHUB_PROXY}${ohmyzsh_url}"
fi
RUNZSH=no CHSH=no sh -c "$(curl -fsSL "$ohmyzsh_url")" || true
else
log_warn "oh-my-zsh already installed"
fi
local plugin_dir="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-history-substring-search"
if [ ! -d "$plugin_dir" ]; then
log_info "Installing zsh-history-substring-search plugin..."
local git_url="https://github.com/zsh-users/zsh-history-substring-search"
if [ "$IS_CHINA" = true ]; then
git_url="${GITHUB_PROXY}${git_url}"
fi
git clone "$git_url" "$plugin_dir"
fi
log_success "Zsh installed successfully"
else
log_warn "Skipping zsh installation"
fi
}
install_zoxide() {
log_header "Zoxide Installation"
if command_exists zoxide; then
log_warn "Zoxide is already installed ($(zoxide --version))"
return 1
fi
if ask_yn "Install zoxide (smart cd command)?" "y"; then
log_info "Installing zoxide..."
brew install zoxide
log_success "Zoxide installed successfully"
else
log_warn "Skipping zoxide installation"
fi
}
install_lazygit() {
log_header "Lazygit Installation"
if command_exists lazygit; then
log_warn "Lazygit is already installed ($(lazygit --version))"
return 1
fi
if ask_yn "Install lazygit (terminal UI for git)?" "y"; then
log_info "Installing lazygit..."
brew install lazygit
log_success "Lazygit installed: $(lazygit --version)"
else
log_warn "Skipping lazygit installation"
fi
}
install_lazydocker() {
log_header "Lazydocker Installation"
if command_exists lazydocker; then
log_warn "Lazydocker is already installed"
return 1
fi
if ask_yn "Install lazydocker (terminal UI for docker)?" "y"; then
log_info "Installing lazydocker..."
brew install lazydocker
log_success "Lazydocker installed successfully"
else
log_warn "Skipping lazydocker installation"
fi
}
install_docker() {
log_header "Docker Installation"
if command_exists docker; then
log_warn "Docker is already installed ($(docker --version))"
if ! ask_yn "Reinstall docker?" "n"; then
return 1
fi
fi
if ask_yn "Install Docker Desktop for Mac?" "y"; then
log_info "Installing Docker Desktop..."
brew install --cask docker
log_info "Docker Desktop installed. Please start Docker Desktop from Applications."
log_success "Docker installed: $(docker --version 2>/dev/null || echo 'Docker Desktop installed')"
else
log_warn "Skipping docker installation"
fi
}
install_neovim() {
log_header "Neovim Installation"
if command_exists nvim; then
log_warn "Neovim is already installed ($(nvim --version | head -n1))"
if ! ask_yn "Reinstall neovim?" "n"; then
return 1
fi
fi
if ask_yn "Install Neovim?" "y"; then
log_info "Installing Neovim..."
brew install neovim
log_success "Neovim installed: $(nvim --version | head -n1)"
else
log_warn "Skipping neovim installation"
fi
}
install_uv() {
log_header "UV Installation (Python Package Manager)"
if command_exists uv; then
log_warn "UV is already installed ($(uv --version))"
return 1
fi
if ask_yn "Install UV (ultrafast Python package manager)?" "y"; then
log_info "Installing UV..."
brew install uv
log_success "UV installed successfully"
else
log_warn "Skipping UV installation"
fi
}
install_poetry() {
log_header "Poetry Installation"
if command_exists poetry; then
log_warn "Poetry is already installed ($(poetry --version))"
return 1
fi
if ask_yn "Install Poetry?" "y"; then
log_info "Installing Poetry..."
brew install poetry
log_success "Poetry installed successfully"
else
log_warn "Skipping Poetry installation"
fi
}
install_luarocks() {
log_header "LuaRocks Installation"
if command_exists luarocks; then
log_warn "LuaRocks is already installed ($(luarocks --version))"
return 1
fi
if ask_yn "Install LuaRocks (Lua package manager)?" "y"; then
log_info "Installing LuaRocks..."
brew install luarocks
log_success "LuaRocks installed: $(luarocks --version)"
else
log_warn "Skipping LuaRocks installation"
fi
}
install_nodejs() {
log_header "Node.js Installation"
if command_exists node; then
log_warn "Node.js is already installed ($(node --version))"
if ! ask_yn "Reinstall Node.js?" "n"; then
return 1
fi
fi
if ask_yn "Install Node.js LTS?" " log_info "y"; then
Installing Node.js LTS..."
brew install node@20
brew link --overwrite node@20
log_success "Node.js installed: $(node --version)"
if ask_yn "Install yarn and pnpm?" "y"; then
npm install -g yarn pnpm
log_success "Global packages installed"
fi
else
log_warn "Skipping Node.js installation"
fi
}
install_gcc() {
log_header "GCC & Build Tools Installation"
if command_exists gcc; then
log_warn "GCC is already installed ($(gcc --version | head -n1))"
return 1
fi
if ask_yn "Install GCC and build tools?" "y"; then
log_info "Installing GCC and build tools..."
brew install gcc make cmake
log_success "GCC installed successfully: $(gcc --version | head -n1)"
else
log_warn "Skipping GCC installation"
fi
}
install_btop() {
log_header "Btop Installation"
if command_exists btop; then
log_warn "Btop is already installed"
return 1
fi
if ask_yn "Install btop (modern system monitor)?" "y"; then
log_info "Installing btop..."
brew install btop
log_success "Btop installed successfully"
else
log_warn "Skipping btop installation"
fi
}
install_tmux() {
log_header "Tmux Installation"
if command_exists tmux; then
log_warn "Tmux is already installed ($(tmux -V))"
return 1
fi
if ask_yn "Install tmux (terminal multiplexer)?" "y"; then
brew install tmux
log_success "Tmux installed: $(tmux -V)"
else
log_warn "Skipping tmux installation"
fi
}
install_fzf() {
log_header "Fzf Installation"
if command_exists fzf; then
log_warn "Fzf is already installed ($(fzf --version))"
return 1
fi
if ask_yn "Install fzf (fuzzy finder)?" "y"; then
brew install fzf
log_success "Fzf installed: $(fzf --version)"
else
log_warn "Skipping fzf installation"
fi
}
install_ripgrep_fd() {
log_header "Ripgrep & Fd Installation"
if ask_yn "Install ripgrep & fd?" "y"; then
if ! command_exists rg; then
log_info "Installing ripgrep..."
brew install ripgrep
fi
if ! command_exists fd; then
log_info "Installing fd..."
brew install fd
fi
log_success "Ripgrep & fd installed successfully"
else
log_warn "Skipping ripgrep & fd installation"
fi
}
install_bun() {
log_header "Bun Installation"
if command_exists bun; then
log_warn "Bun is already installed ($(bun --version))"
return 1
fi
if ask_yn "Install Bun (fast JavaScript runtime)?" "y"; then
log_info "Installing Bun..."
# Bun is not available in Homebrew core, use official installer
local bun_url="https://bun.sh/install"
if [ "$IS_CHINA" = true ]; then
bun_url="${GITHUB_PROXY}https://github.com/oven-sh/bun/install.sh"
fi
curl -fsSL "$bun_url" | bash
if command_exists bun; then
log_success "Bun installed successfully"
else
# Source the shell config to make bun available
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
if [ -f "$BUN_INSTALL/bin/bun" ]; then
log_success "Bun installed successfully (restart terminal to use)"
else
log_error "Failed to install Bun"
fi
fi
else
log_warn "Skipping Bun installation"
fi
}
install_ghostty() {
log_header "Ghostty Terminal Installation"
if command_exists ghostty; then
log_warn "Ghostty is already installed"
return 1
fi
if ask_yn "Install Ghostty terminal?" "y"; then
log_info "Installing Ghostty..."
brew install --cask ghostty
# Create config directory
mkdir -p "$HOME/.config/ghostty"
# Backup existing config
backup_path "$HOME/.config/ghostty/config"
# Write Ghostty configuration
cat > "$HOME/.config/ghostty/config" << 'GHOSTTY_CONFIG'
# ============================================
# Ghostty Terminal - Complete Configuration
# ============================================
# File: ~/.config/ghostty/config
# Reload: Cmd+Shift+, (macOS)
# View options: ghostty +show-config --default --docs
# --- Typography ---
font-family = "Maple Mono NF CN"
font-size = 14
font-thicken = true
adjust-cell-height = 2
# --- Theme and Colors ---
# Catppuccin with automatic light/dark switching
theme = Catppuccin Mocha
# --- Window and Appearance ---
background-opacity = 0.85
background-blur-radius = 30
macos-titlebar-style = transparent
window-padding-x = 10
window-padding-y = 8
window-save-state = always
window-theme = auto
# --- Cursor ---
cursor-style = bar
cursor-style-blink = true
cursor-opacity = 0.8
# --- Mouse ---
mouse-hide-while-typing = true
copy-on-select = clipboard
# --- Quick Terminal (Quake-style dropdown) ---
quick-terminal-position = top
quick-terminal-screen = mouse
quick-terminal-autohide = true
quick-terminal-animation-duration = 0.15
# --- Security ---
clipboard-paste-protection = true
clipboard-paste-bracketed-safe = true
# --- Shell Integration ---
shell-integration = detect
# --- Keybindings ---
# Tabs
keybind = cmd+t=new_tab
keybind = cmd+shift+left=previous_tab
keybind = cmd+shift+right=next_tab
keybind = cmd+w=close_surface
# Splits
keybind = cmd+d=new_split:right
keybind = cmd+shift+d=new_split:down
keybind = cmd+alt+left=goto_split:left
keybind = cmd+alt+right=goto_split:right
keybind = cmd+alt+up=goto_split:top
keybind = cmd+alt+down=goto_split:bottom
# Font size
keybind = cmd+plus=increase_font_size:1
keybind = cmd+minus=decrease_font_size:1
keybind = cmd+zero=reset_font_size
# Quick terminal global hotkey
keybind = global:ctrl+grave_accent=toggle_quick_terminal
# Splits management
keybind = cmd+shift+e=equalize_splits
keybind = cmd+shift+f=toggle_split_zoom
# Reload config
keybind = cmd+shift+comma=reload_config
# --- Performance ---
# Generous scrollback (25MB)
scrollback-limit = 25000000
GHOSTTY_CONFIG
log_success "Ghostty installed and configured successfully"
log_info "Config file: ~/.config/ghostty/config"
log_info "Note: You may need to install 'Maple Mono NF CN' font for best experience"
else
log_warn "Skipping Ghostty installation"
fi
}
install_claude() {
log_header "Claude CLI Installation"
if command_exists claude; then
log_warn "Claude CLI is already installed ($(claude --version 2>/dev/null || echo 'installed'))"
return 1
fi
if ask_yn "Install Claude CLI with domestic network configuration?" "y"; then
log_info "Installing Claude CLI..."
# Install claude CLI via npm
npm install -g @anthropic-ai/claude-code
if ! command_exists claude; then
log_error "Failed to install Claude CLI"
return 1
fi
# Create Claude config directory
mkdir -p "$HOME/.claude"
# Configure for domestic network (China proxy)
# Create settings.json with proxy and API configuration
cat > "$HOME/.claude/settings.json" << 'CLAUDE_SETTINGS'
{
"apiProvider": "anthropic",
"apiBaseUrl": "https://api.anthropic.com",
"defaultModel": "claude-sonnet-4-6",
"enableProxy": true,
"proxyUrl": "http://127.0.0.1:7890"
}
CLAUDE_SETTINGS
# Create .claude.json for project-level settings
cat > "$HOME/.claude.json" << 'CLAUDE_PROJECT'
{
"model": "claude-sonnet-4-6"
}
CLAUDE_PROJECT
log_success "Claude CLI installed successfully"
log_info "Configured with domestic network proxy support"
log_info "Config file: ~/.claude/settings.json"
log_warn "Note: Make sure your proxy is running on http://127.0.0.1:7890"
log_warn "Or update the proxy URL in ~/.claude/settings.json"
else
log_warn "Skipping Claude CLI installation"
fi
}
configure_bailian_subscription() {
log_header "Alibaba Cloud Bailian (百炼) Subscription Configuration"
if ask_yn "Configure Alibaba Cloud Bailian coding plan subscription?" "y"; then
# Create .claude directory if not exists
mkdir -p "$HOME/.claude"
# Backup existing settings
backup_path "$HOME/.claude/settings.json"
# Configure Bailian API with Anthropic compatible endpoint
cat > "$HOME/.claude/settings.json" << 'BAILIAN_CONFIG'
{
"env": {
"ANTHROPIC_AUTH_TOKEN": "YOUR_API_KEY",
"ANTHROPIC_BASE_URL": "https://coding.dashscope.aliyuncs.com/apps/anthropic",
"ANTHROPIC_MODEL": "qwen3.5-plus"
}
}
BAILIAN_CONFIG
log_success "Bailian subscription configured"
log_info "Default model: qwen3.5-plus"
log_info "Config file: ~/.claude/settings.json"
log_warn "IMPORTANT: You need to replace YOUR_API_KEY with your actual API key"
log_warn " Edit ~/.claude/settings.json and update ANTHROPIC_AUTH_TOKEN"
else
log_warn "Skipping Bailian subscription configuration"
fi
}
configure_zsh() {
log_header "Zsh Configuration"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
log_warn "oh-my-zsh not installed, skipping zsh configuration"
return 1
fi
backup_path "$HOME/.zshrc"
cat > "$HOME/.zshrc" << 'EOF'
export PATH="/opt/homebrew/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git docker zoxide fzf zsh-history-substring-search)
source $ZSH/oh-my-zsh.sh
if command -v zoxide >/dev/null 2>&1; then
eval "$(zoxide init zsh)"
fi
HISTSIZE=10000
SAVEHIST=10000
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_FIND_NO_DUPS
setopt HIST_SAVE_NO_DUPS
alias vim='nvim'
alias vi='nvim'
alias lg='lazygit'
alias ld='lazydocker'
EOF
log_success "Zsh configured successfully"
if [ "$SHELL" != "$(which zsh)" ]; then
if ask_yn "Set zsh as default shell?" "y"; then
chsh -s "$(which zsh)"
log_success "Default shell changed to zsh"
fi
fi
}
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
-y|--yes)
AUTO_YES=true
shift
;;
-h|--help)
cat << EOF
macOS (Intel/x86_64) Server Setup Script
Usage: $0 [OPTIONS]
OPTIONS:
-y, --yes Auto-answer yes to all prompts (non-interactive mode)
-h, --help Display this help message
EXAMPLES:
$0 # Interactive mode with prompts
$0 -y # Non-interactive mode, auto-yes to everything
For more information, see README.md
EOF
exit 0
;;
*)
log_error "Unknown option: $1"
echo "Use -h or --help for usage information"
exit 1
;;
esac
done
}
main() {
parse_args "$@"
if [ "$AUTO_YES" = true ]; then
log_info "Running in AUTO-YES mode - all prompts will be automatically accepted"
fi
log_header "macOS (Intel/x86_64) Setup"
check_installation_status
if ! ask_yn "Continue with installation?" "y"; then
log_info "Installation cancelled"
exit 0
fi
check_prerequisites
install_git || true
install_zsh || true
install_zoxide || true
install_lazygit || true
install_lazydocker || true
install_docker || true
install_neovim || true
install_uv || true
install_poetry || true
install_luarocks || true
install_nodejs || true
install_gcc || true
install_btop || true
install_tmux || true
install_fzf || true
install_ripgrep_fd || true
install_bun || true
install_ghostty || true
install_claude || true
configure_bailian_subscription || true
configure_zsh || true
log_header "Installation Complete"
log_success "All requested tools have been installed"
log_info "Log file: $LOG_FILE"
log_info "Note: Some tools may require restarting terminal or logging out/in"
}
main "$@"