前提条件
-
确保你的macOS系统已安装Homebrew(包管理器)
# 检查是否安装homebrew brew --version # 下载homebrew:官方镜像源 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" -
确保已安装Git(新mac通常已预装)
# 检查是否已安装git git --version -
确保已安装并使用zsh(macOS Catalina 及更高版本默认使用 zsh)
# 检查是否已安装 zsh zsh --version # 如果未安装,使用 Homebrew 安装 brew install zsh # 设置zsh为默认shell chsh -s /bin/zsh
安装oh-my-zsh
官方下载文档链接:https://github.com/ohmyzsh/ohmyzsh/wiki
# mac用户建议直接使用crul
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
看到欢迎页面就算安装完成了
配置oh-my-zsh
基本所有oh-my-zsh的配置都是在~/.zshrc中进行配置
oh-my-zsh配置文件zshrc打开方式
可以自选自己喜欢的编辑器编辑文件,以下只列出三个主流的
-
VSCODE打开
code ~/.zshrc -
vim 打开
vim ~/.zshrc -
Nano打开
nano ~/.zshrc
中文文件路径乱码问题修复
若你执行ls时遇见了中文文件显示乱码的问题,可以通过以下方式解决
# 在~/.zshrc文件中末尾添加以下行并保存
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
shell执行重启zsh
# 运行zsh
source ~/.zshrc
插件推荐
1. zsh-autosuggestions 历史补全
# zsh-autosuggestions 历史补全下载
# shell 输入以下命令
brew install --formulae zsh-autosuggestions
在~/.zshrc文件中末尾添加以下行
# 配置文件: ~/.zshrc
# 功能: 启用 zsh-autosuggestions
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
保存后shell执行重启zsh
# 运行zsh
source ~/.zshrc
2. zsh-completions 额外补全
# zsh-completions 额外补全下载
# shell 执行以下命令
brew install --formulae zsh-completions
# 您可能需要重建`zcompdump`
rm -f ~/.zcompdump; compinit
# 另外,如果你执行`source ~/.zshrc`时出现了以下警告
# "zsh compinit: insecure directories"
# shell执行以下命令以解决
chmod go-w '/opt/homebrew/share'
chmod -R go-w '/opt/homebrew/share/zsh'
在~/.zshrc文件中末尾添加以下行
# 配置文件: ~/.zshrc
# 功能: 启用 zsh-completions
if type brew &>/dev/null; then
FPATH=$(brew --prefix)/share/zsh-completions:$FPATH
autoload -Uz compinit
compinit
fi
保存后shell执行重启zsh
# 运行zsh
source ~/.zshrc
3. zsh-syntax-highlighting 语法高亮
# zsh-syntax-highlighting 语法高亮下载
# shell 执行以下命令
brew install --formulae zsh-syntax-highlighting
在~/.zshrc文件中末尾添加以下行
# 配置文件: ~/.zshrc
# 功能: 启用 zsh-syntax-highlighting
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
保存后shell执行重启zsh
# 运行zsh
source ~/.zshrc
5237

被折叠的 条评论
为什么被折叠?



