1. 基础网络与包管理工具
新机器落地的第一步,永远是搞定网络和包管理器。
终端代理配置
不使用代理会严重影响后续诸如 Homebrew、GitHub 仓库等资源的下载速度。
# 将 [your port] 替换为你代理软件的实际本地端口(例如 7890) echo "alias proxy_off='unset http_proxy; unset https_proxy; unset all_proxy'" >> ~/.zshrc echo "alias proxy_on='export https_proxy=[http://127.0.0.1](http://127.0.0.1):[your port];export http_proxy=[http://127.0.0.1](http://127.0.0.1):[your port];export all_proxy=socks5://127.0.0.1:[your port]'" >> ~/.zshrc source ~/.zshrc # 立即开启代理 proxy_on
Homebrew 与 Git
安装 macOS 必备的包管理器 Homebrew,并配置全局的 Git 信息。
# 下载 Homebrew /bin/bash -c "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh](https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh))" # 添加 homebrew 到 $PATH echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile source ~/.zprofile # 配置 Git (请替换为你的真实信息) git config --global user.name "John Doe" git config --global user.email "[email protected]" git config --global core.editor nvim git config --global init.defaultBranch main
2. 终端体验与 Shell 优化
NeoVim 与 Wezterm
我不把 Vim 作为主力 IDE,而是用它来快速编辑终端里的各种配置文件。终端模拟器我选择了高度可定制的 Wezterm。
# 懒得配置 Neo Vim 的我决定懒鬼的使用 LazyVim 的预设 brew install neovim git clone https://github.com/LazyVim/starter ~/.config/nvim rm -rf ~/.config/nvim/.git # 下载 Wezterm brew install --cask wezterm mkdir ~/.config/wezterm touch ~/.config/wezterm/wezterm.lua # 下载你喜欢的 Nerd Font 字体(我用的是 Fira Mono Nerd Font,你可以在https://www.nerdfonts.com/font-downloads挑选字体并用homebrew下载) brew install font-fira-mono-nerd-font
下面是我Wezterm的完整配置文件,包含了主题、字体、快捷键等个性化设置。你可以直接复制粘贴到你的 ~/.config/wezterm/wezterm.lua 中,并根据需要进行调整。其中,你需要注意调整背景图片的路径(~/.assets/background.jpg)以匹配你自己的文件位置。
Wezterm 配置文件 (wezterm.lua)
先创建配置文件
mkdir -p ~/.config/wezterm touch ~/.config/wezterm/wezterm.lua
然后在 ~/.config/wezterm/wezterm.lua 中写入你的配置
-- wezterm.lua
-- This config strongly refers to Josean Martinez's tutorial
local wezterm = require("wezterm")
local config = wezterm.config_builder()
config.automatically_reload_config = true
config.window_close_confirmation = "NeverPrompt"
config.window_decorations = "RESIZE"
config.enable_tab_bar = true
config.default_cursor_style = "BlinkingBar"
config.color_scheme = "Nord (Gogh)"
config.font = wezterm.font("FiraMono Nerd Font", { weight = "Regular", stretch = "Normal", style = "Normal" })
config.background = {
{
source = {
File = wezterm.home_dir .. "/.assets/background.jpg", -- Update your path
},
hsb = { hue = 1.0, saturation = 1.02, brightness = 0.25 },
},
{
source = { Color = "#282c35" },
opacity = 0.55,
},
}
config.window_padding = { top = 0, bottom = 0, left = 3, right = 3 }
config.default_prog = { "/bin/zsh", "-l" }
config.enable_scroll_bar = true
config.scrollback_lines = 10000
config.font_size = 14.0
-- Keybindings
config.keys = {
{ key = "v", mods = "CTRL|SHIFT", action = wezterm.action.PasteFrom("Clipboard") },
{ key = "c", mods = "CTRL|SHIFT", action = wezterm.action.CopyTo("Clipboard") },
{ key = "Enter", mods = "ALT", action = wezterm.action.SplitHorizontal({ domain = "CurrentPaneDomain" }) },
{ key = "Enter", mods = "CTRL|ALT", action = wezterm.action.SplitVertical({ domain = "CurrentPaneDomain" }) },
{ key = "h", mods = "CTRL|ALT", action = wezterm.action.ActivatePaneDirection("Left") },
{ key = "l", mods = "CTRL|ALT", action = wezterm.action.ActivatePaneDirection("Right") },
{ key = "k", mods = "CTRL|ALT", action = wezterm.action.ActivatePaneDirection("Up") },
{ key = "j", mods = "CTRL|ALT", action = wezterm.action.ActivatePaneDirection("Down") },
{ key = "n", mods = "CTRL|SHIFT", action = wezterm.action.SpawnTab("CurrentPaneDomain") },
{ key = "x", mods = "CTRL|SHIFT", action = wezterm.action.CloseCurrentPane({ confirm = false }) },
}
return config
Starship 与 Zsh 增强组件
使用 Starship 美化终端提示符(使用 Gruvbox Rainbow 主题),并安装现代化的 CLI 替代工具。
brew install starship zsh-autosuggestions zsh-syntax-highlighting zsh-completions brew install eza zoxide fzf bat ripgrep fd # 初始化 Starship echo 'eval "$(starship init zsh)"' >> ~/.zshrc starship preset gruvbox-rainbow -o ~/.config/starship.toml
其中,eza是ls的现代化替代品,支持图标和更丰富的输出;zoxide是cd的增强版本,支持模糊匹配和快速跳转;bat是cat的增强版本,支持语法高亮和分页显示;ripgrep是grep的快速替代品;fd则是find的现代化替代品。更多相关的个性化配置和使用可以参考它们分别的官方文档。
3. Dotfiles 统一管理 (GNU Stow)
随着配置文件的增多,使用 stow 通过软链接来集中管理它们是最高效的做法。
brew install stow mkdir -p ~/.dotfiles # 创建目录结构并移动现有配置 mkdir -p ~/.dotfiles/zsh && mv ~/.zshrc ~/.dotfiles/zsh/ mkdir -p ~/.dotfiles/git && mv ~/.gitconfig ~/.dotfiles/git/ mkdir -p ~/.dotfiles/nvim/.config && mv ~/.config/nvim ~/.dotfiles/nvim/.config/ mkdir -p ~/.dotfiles/wezterm/.config && mv ~/.config/wezterm ~/.dotfiles/wezterm/.config/ mkdir -p ~/.dotfiles/starship/.config && mv ~/.config/starship.toml ~/.dotfiles/starship/.config/ # 使用 stow 重新生成软链接到 ~ 目录 stow -d ~/.dotfiles -t ~ git nvim wezterm starship zsh
4. 语言与开发环境
数据科学:Python (Miniforge)
对于 AI 和数据清洗工作,我偏好使用由社区维护的 Miniforge。相比于 Anaconda,它更轻量且原生支持 Apple Silicon。
brew install --cask miniforge conda init zsh # 关闭默认激活 base 环境,防止污染全局并拖慢终端启动速度 conda config --set auto_activate false # 创建稳定基础的数据科学环境 conda create -n ds-base-py311 python=3.11 pandas numpy matplotlib jupyterlab
综合开发:Mise
对于其他语言版本管理,我放弃了 nvm、gvm 等零散的工具,统一使用 mise。
brew install mise echo '\n# mise\neval "$(mise activate zsh)"' >> ~/.dotfiles/zsh/.zshrc mise use --global node@20 mise use --global go@latest mise use --global [email protected] [email protected] # 额外配置 go 环境变量 echo '\n# Golang\nexport PATH="$HOME/go/bin:$PATH"' >> ~/.dotfiles/zsh/.zshrc
5. VS Code:我仍然是世一 IDE
由于我们要用 stow 管理 VS Code 配置,所以在首次启动软件前,我们需要预先建立好配置文件的软链接。
brew install --cask visual-studio-code # 创建 VS Code 配置存储结构 mkdir -p ~/.dotfiles/vscode/Library/Application\ Support/Code/User/snippets/ touch ~/.dotfiles/vscode/Library/Application\ Support/Code/User/settings.json touch ~/.dotfiles/vscode/Library/Application\ Support/Code/User/keybindings.json # 构建软链接 stow -d ~/.dotfiles -t ~ vscode
插件自动化管理
我通过一个 Shell 脚本配合 extensions.txt 清单来管理VS Code插件。你可以直接在我的开源仓库里找到 extensions.txt 和 install_vscode_extensions.sh。
VS Code 插件清单 (extensions.txt)
我将插件清单放在 ~/.dotfiles/vscode/extensions.txt 中:
# theme catppuccin.catppuccin-vsc catppuccin.catppuccin-vsc-icons # general esbenp.prettier-vscode usernamehw.errorlens eamodio.gitlens ms-vscode-remote.remote-ssh mushan.vscode-paste-image drcika.apc-extension # appearence mechatroner.rainbow-csv # python ms-python.python ms-toolsai.jupyter charliermarsh.ruff # golang golang.go # latex james-yu.latex-workshop # astro astro-build.astro-vscode bradlc.vscode-tailwindcss # markdown yzhang.markdown-all-in-one # markdoc stripe.markdoc-language-support # html formulahendry.auto-rename-tag
VS Code 插件安装脚本 (install_vscode_extensions.sh)
下面的脚本放在 ~/.dotfiles/ 下,它会读取 extensions.txt 中的插件列表并自动安装。你可以直接复制粘贴到 install_vscode_extensions.sh 中,并赋予执行权限后运行。
#!/bin/bash echo "Installing VS Code extensions..." cat ~/.dotfiles/vscode/extensions.txt | grep -v '^#' | xargs -L 1 code --install-extension echo "Extensions all installed."
# 赋予脚本执行权限并运行 chmod +x ~/.dotfiles/install_vscode_extensions.sh bash ~/.dotfiles/install_vscode_extensions.sh
VS Code 完整全局配置 (settings.json)
将下面的设置粘贴到~/.dotfiles/vscode/Library/Application Support/Code/User/settings.json中以使用这些设置。
{
// ==========================================
// Theme & Appearance
// ==========================================
"workbench.colorTheme": "Catppuccin Frappé",
"workbench.iconTheme": "catppuccin-vsc-icons",
"editor.fontFamily": "'Fira Code', 'Jetbrains Mono', monospace",
"editor.fontLigatures": true,
"editor.fontSize": 20,
"editor.lineHeight": 1.5,
// Custom UI via Apc Customize UI++
"apc.font.family": "Fira Code, JetBrains Mono, monospace",
"apc.parts.font.family": {
"sidebar": "Fira Code",
"titlebar": "Fira Code"
},
"apc.listRow": { "fontSize": 15, "height": 26 },
// ==========================================
// Editor Core & Formatting
// ==========================================
"editor.formatOnSave": true,
"editor.wordWrap": "on",
"files.autoSave": "onFocusChange",
"editor.bracketPairColorization.enabled": true,
"editor.minimap.enabled": false,
"editor.defaultFormatter": "esbenp.prettier-vscode",
// ==========================================
// Python & Golang
// ==========================================
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": { "source.organizeImports": "explicit" }
},
"[go]": {
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": { "source.organizeImports": "explicit" }
},
// ==========================================
// Markdown & Markdoc
// ==========================================
"[markdown]": { "editor.defaultFormatter": "yzhang.markdown-all-in-one" },
"files.associations": {
"*.mdoc": "markdoc"
},
// ==========================================
// LaTeX Workshop (Auto-Build on Save)
// ==========================================
"latex-workshop.latex.autoBuild.run": "onSave",
"latex-workshop.view.pdf.viewer": "tab",
"latex-workshop.latex.tools": [
{
"name": "latexmk",
"command": "latexmk",
"args": ["-synctex=1", "-interaction=nonstopmode", "-file-line-error", "-pdf", "-outdir=%OUTDIR%", "%DOC%"]
}
],
"latex-workshop.latex.recipes": [
{ "name": "latexmk 🔃", "tools": ["latexmk"] }
],
"latex-workshop.latex.autoClean.run": "onBuilt",
// ==========================================
// Misc
// ==========================================
"errorLens.delay": 300,
"errorLens.fontStyleItalic": true,
"workbench.startupEditor": "none"
}
6. 系统增强:窗口管理与快捷启动
AeroSpace 窗口管理器
我使用 AeroSpace 而不是 Yabai,主要因为它不需要修改 macOS 的底层系统完整性保护(SIP),而且在MacOS进行大版本更新后也不容易崩溃,并且使用基于平铺(Tiling)的树状逻辑。
brew install --cask nikitabobko/tap/aerospace mkdir -p ~/.dotfiles/aerospace/.config/aerospace
AeroSpace 快捷键配置 (aerospace.toml)
# aerospace.toml start-at-login = true accordion-padding = 30 default-root-container-layout = 'tiles' default-root-container-orientation = 'auto' [gaps] inner.horizontal = 10 inner.vertical = 10 outer.left = 10 outer.bottom = 10 outer.top = 10 outer.right = 10 [mode.main.binding] # Layout alt-slash = 'layout tiles horizontal vertical' alt-comma = 'layout accordion horizontal vertical' # Focus alt-h = 'focus left' alt-j = 'focus down' alt-k = 'focus up' alt-l = 'focus right' # Move alt-shift-h = 'move left' alt-shift-j = 'move down' alt-shift-k = 'move up' alt-shift-l = 'move right' # Workspaces alt-1 = 'workspace 1' alt-2 = 'workspace 2' alt-w = 'workspace w' alt-a = 'workspace a' # Move to Workspaces alt-shift-1 = 'move-node-to-workspace 1' alt-shift-w = 'move-node-to-workspace w' # w specially for Wezterm alt-shift-a = 'move-node-to-workspace a' # a specially for Arc # Fullscreen alt-shift-f = 'fullscreen' # Service Mode alt-shift-semicolon = 'mode service' [mode.service.binding] esc = ['reload-config', 'mode main'] r = ['flatten-workspace-tree', 'mode main'] f = ['layout floating tiling', 'mode main'] backspace = ['close-all-windows-but-current', 'mode main']
Raycast 启动器
Raycast 是目前最强的 Spotlight 替代品。我通过Cmd + Space的快捷键启动 Raycast,因此安装后需要在 macOS 设置中取消 Spotlight 默认的 Cmd + Space 快捷键。我会为 Bilibili、GitHub、YouTube 甚至 Google 翻译配置专属的 Quicklinks,大幅提升搜索效率。
7. CLI 工具与其他日常软件 (通过Brewfile)
最后,将所有剩下的常用软件、浏览器(Arc / Chrome)、笔记工具(Notion / Obsidian)统统写进 Brewfile,进行一键自动化下载。
我的完整软件清单 (Brewfile)
下面是我的使用的主要软件的清单,包含了开发工具、AI 工具、生产力软件、媒体设计工具、社交通讯软件以及各种实用工具。你可以直接复制粘贴到你的 Brewfile 中,并根据需要进行调整。其中微信和QQ音乐用brew下载很可能出错,因此建议直接从App Store下载。
# ~/.dotfiles/Brewfile # Developer Tools cask "cursor" cask "pycharm" # AI Tools cask "chatgpt" cask "lm-studio" cask "ollama-app" # Productivity cask "arc" cask "coteditor" cask "google-chrome" cask "notion" cask "obsidian" cask "updf" cask "zotero" # Media & Design cask "iina" cask "obs" cask "mactex" # Social & Comm (WeChat / QQ Music are better downloaded via App Store) cask "neteasemusic" cask "qq" cask "tencent-meeting" # Utilities cask "appcleaner" cask "battery-buddy" cask "keepingyouawake" cask "mos" cask "tailscale-app" cask "the-unarchiver" cask "raycast" # CLI Tools brew "jq" brew "tldr" brew "yt-dlp" brew "btop"
# 切换到 Brewfile 所在目录并一键执行下载 cd ~/.dotfiles brew bundle
至此,这台 Mac 已经被调教完毕了。