使用 Hola 在几分钟内设置您的 Mac 开发环境
发布: (2025年12月4日 GMT+8 11:56)
4 min read
原文: Dev.to
Source: Dev.to
为什么选择 Hola?
- 没有像传统 Chef 那样的沉重依赖。
- Ruby DSL 可读且富有表现力,但对大多数用户来说是可选的。
- 在同一工作流中处理 Homebrew、mise、dotfiles 和 macOS 系统设置。
- 使用 Zig 构建,速度快且内存占用极小。
功能
约定优于配置
使用你已经熟悉的工具:
Brewfile(Homebrew 原生格式)
brew "git"
brew "neovim"
cask "ghostty"
cask "visual-studio-code"
mise.toml(mise 原生格式)
[tools]
node = "24"
python = "3.14"
rust = "stable"
可选的 Ruby DSL
用于高级配置(90 % 的用户不需要):
# ~/.config/hola/provision.rb
package ["git", "tmux", "neovim"]
execute "install-oh-my-zsh" do
command 'sh -c "$(curl -fsSL https://ohmyz.sh/install.sh)"'
not_if { Dir.exist?(File.expand_path("~/.oh-my-zsh")) }
end
智能 Dotfiles 管理
# 从 GitHub 仓库引导(克隆 + 安装包 + 链接 dotfiles)
hola apply --github username/dotfiles
# 或者仅从本地目录链接 dotfiles
hola link --dotfiles ~/.dotfiles
macOS 桌面配置
在 Ruby 中直接定义 Dock 布局和系统默认设置:
# ~/.config/hola/provision.rb
macos_dock do
apps [
'/Applications/Ghostty.app/',
'/Applications/Visual Studio Code.app/',
'/Applications/Safari.app/',
]
orientation "bottom"
autohide true
magnification true
tilesize 50
largesize 40
end
macos_defaults "show hidden files" do
domain "com.apple.finder"
key "AppleShowAllFiles"
value true
end
macos_defaults "keyboard repeat rate" do
global true
key "KeyRepeat"
value 1
end
安装
# 快速安装(推荐)
curl -fsSL https://hola.ac/install | bash
或通过 Homebrew:
brew tap ratazzi/hola
brew install hola
或手动下载:
curl -fsSL https://github.com/ratazzi/hola/releases/latest/download/hola-macos-aarch64 -o hola
chmod +x hola
xattr -d com.apple.quarantine hola
sudo mv hola /usr/local/bin/
示例仓库结构
repo/
├── Brewfile
├── mise.toml
└── .config/
└── hola/
└── provision.rb # 可选
Brewfile(仓库根目录)
brew "git"
brew "gh"
brew "ripgrep"
brew "fzf"
cask "ghostty"
cask "zed"
cask "raycast"
mise.toml(仓库根目录)
[tools]
node = "20"
python = "3.12"
go = "latest"
Provision 文件(可选——参见 macOS 桌面配置章节的示例)。
一条命令即可完成全部设置:
hola apply --github username/dotfiles
Hola 的工作原理
- ✅ 将你的 dotfiles 仓库克隆到
~/.dotfiles - ✅ 从
Brewfile安装所有 Homebrew 包 - ✅ 从
mise.toml安装并固定工具版本 - ✅ 将 dotfiles 软链接到你的主目录
- ✅ 运行
provision.rb(如果存在)以配置 Dock 和系统设置
导出现有配置
# 导出当前 Dock 配置
hola dock
# 导出 Homebrew 包到 Brewfile
brew bundle dump
公司级 Dotfiles 仓库示例
Brewfile
# 每位开发者都需要的核心工具
brew "git"
brew "docker"
brew "kubectl"
# 公司特定工具
cask "slack"
cask "zoom"
cask "visual-studio-code"
Provision 文件(高级设置)
# 安装 VS Code 扩展
execute "install vscode extensions" do
command "code --install-extension ms-python.python"
command "code --install-extension dbaeumer.vscode-eslint"
not_if "code --list-extensions | grep -q ms-python.python"
end
# 克隆团队仓库
directory "/Users/#{ENV['USER']}/work" do
recursive true
end
git "/Users/#{ENV['USER']}/work/backend" do
repository "git@github.com:company/backend.git"
end
新员工只需运行:
hola apply --github company/dotfiles
高级 Ruby DSL 用法
# 在 ~/.config/hola/provision.rb 中
if ENV['USER'] == 'john'
package "discord"
end
case node['platform']
when 'darwin'
package "mas" # Mac App Store CLI
when 'ubuntu'
apt_repository "ppa:graphics-drivers/ppa"
end
template "/Users/#{ENV['USER']}/.gitconfig" do
content "它像 Chef,但没有负担。"
end
“终于有了可用的 Dock 管理。” – 再也不需要手动拖拽或编写复杂的 AppleScript。用代码定义 Dock 布局。
“约定优于配置做得恰到好处。” – 智能默认值让你少敲很多字。Hola 知道 dotfiles 应该放在哪里。
入门指南
# 安装
curl -fsSL https://hola.ac/install | bash
# 从你的 dotfiles 仓库引导
hola apply --github username/dotfiles
或仅使用一个 Brewfile 简单开始:
echo 'brew "git"' > Brewfile
echo 'cask "ghostty"' >> Brewfile
hola apply
链接
由热爱时间的开发者使用 Zig ❤️ 构建。