一、前置确认(M1 很重要)
macOS 默认 shell 基本都是 zsh,但先确认一下:
echo $SHELL
如果不是 /bin/zsh,切换:
chsh -s /bin/zsh
重启终端生效。
二、安装 oh-my-zsh(国内可用方案)
✅ 方案一:使用 Gitee 镜像(强烈推荐)
官方 GitHub 在大陆不稳定,直接用 Gitee 镜像。
export ZSH="$HOME/.oh-my-zsh"
git clone https://gitee.com/mirrors/oh-my-zsh.git $ZSH
复制模板配置:
cp $ZSH/templates/zshrc.zsh-template ~/.zshrc
重新加载:
source ~/.zshrc
看到终端样式变化,说明 oh-my-zsh 已成功 🎉
❌ 不推荐
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
在大陆 极容易失败 / 卡死
三、M1 建议的基础环境(Homebrew)
安装 Homebrew(Apple Silicon 官方路径)
/bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"
安装完成后,确认路径:
brew --prefix
M1 一般是:
/opt/homebrew
四、安装最常用 & 必装 zsh 插件 ⭐⭐⭐⭐⭐
1️⃣ zsh-autosuggestions(命令历史自动提示)
git clone https://gitee.com/mirrors/zsh-autosuggestions.git \
~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
效果:
输入命令时出现 灰色历史提示,按 → 补全
2️⃣ zsh-syntax-highlighting(语法高亮)
⚠️ 必须放在插件列表最后
git clone https://gitee.com/mirrors/zsh-syntax-highlighting.git \
~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting
效果:
- 绿色:正确命令
- 红色:错误命令
3️⃣ z(目录跳转神器)
brew install z
效果:
z project
z desktop
直接跳到你最常去的目录
4️⃣ extract(万能解压)
oh-my-zsh 自带插件,无需安装:
x file.tar.gz
x file.zip
5️⃣ git(必开)
oh-my-zsh 内置,提供大量 git alias:
gst # git status
gco # git checkout
gl # git pull
gp # git push
五、配置插件(关键一步)
编辑 ~/.zshrc:
vi ~/.zshrc
找到这一行:
plugins=(git)
改成👇(推荐顺序):
plugins=(
git
z
extract
zsh-autosuggestions
zsh-syntax-highlighting
)
⚠️ zsh-syntax-highlighting 必须最后
保存并生效:
source ~/.zshrc
六、推荐主题(M1 + 中文环境友好)
🎨 1️⃣ robbyrussell(默认,稳定)
ZSH_THEME="robbyrussell"
🎨 2️⃣ agnoster(需要 Nerd Font)
ZSH_THEME="agnoster"
安装字体:
brew tap homebrew/cask-fonts
brew install --cask font-hack-nerd-font
终端设置字体为 Hack Nerd Font