如何在 Mac 终端上设置 ZSH
安装 Homebrew
打开终端窗口并使用以下命令安装 homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
将 Homebrew 添加到路径
安装后,将其添加到路径中(将“[username]”替换为你的实际用户名):
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/[username]/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
安装 iTerm2
要安装,请运行:
brew install --cask iterm2
切换到 iTerm2 来完成本演练的剩余部分。
安装 Git
如果你还没有安装,也请安装 git:
brew install git
安装 Oh My Zsh
运行此命令来安装 Oh My Zsh:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
为 Oh My Zsh 安装 PowerLevel10K 主题
运行此命令来安装 PowerLevel10K:
git clone https://github.com/romkatv/powerlevel10k.git $ZSH_CUSTOM/themes/powerlevel10k
现在已经安装好了,打开 zshrc 运行这个命令
nano ~/.zshrc
使用您喜欢的编辑器打开文件并更改“ZSH_THEME”的值,如下所示:
ZSH_THEME="powerlevel10k/powerlevel10k"
要在您的终端上反映此更改,请重新启动它或运行以下命令:
source ~/.zshrc
安装 Meslo Nerd 字体
按“y”安装字体,然后退出 iTerm2。
更新 VSCode 终端字体(可选)
Visual Studio Code 中的 settings.json 文件位于以下位置:
-
macOS:$HOME/Library/Application Support/Code/User/settings.json
-
您还可以通过转到文件 > 首选项 > 设置,然后单击右上角的 {} 图标打开 settings.json 文件,在 Visual Studio Code 中直接访问 settings.json 文件。
打开 settings.json 并添加以下行:
"terminal.integrated.fontFamily": "MesloLGS NF"
Configure PowerLevel10K
重启 iTerm2。现在您应该可以看到 PowerLevel10K 的配置过程了。如果没有看到,请运行以下命令:
p10k configure
按照 PowerLevel10K 配置的说明,使您的终端看起来符合要求。
增加终端字体大小
-
打开 iTerm2 偏好设置
-
前往个人资料 > 文本
-
我将字体大小增加到大约 20px
将 iTerm2 颜色更改为我的自定义主题
-
打开 iTerm2
-
通过运行以下命令下载我的颜色配置文件(将添加到下载文件夹):
curl https://raw.githubusercontent.com/josean-dev/dev-environment-files/main/coolnight.itermcolors --output ~/Downloads/coolnight.itermcolors
-
打开 iTerm2 偏好设置
-
前往配置文件 > 颜色
-
导入下载的颜色配置文件(coolnight)
-
选择颜色配置文件(coolnight)
您可以在这里找到其他主题:Iterm2 配色方案
安装 ZSH 插件
安装 zsh-autosuggestions:
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
安装 zsh-syntax-highlighting:
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
在您想要的编辑器中打开“~/.zshrc”文件并将插件行修改为您在下面看到的内容。
plugins=(git zsh-autosuggestions zsh-syntax-highlighting web-search)
通过运行以下命令加载这些新插件:
source ~/.zshrc
完成啦!
Youtube 视频参考 - https://www.youtube.com/watch?v=CF1tMjvHDRA&t=284s
文章来源:https://dev.to/khairunnaharnowrin/how-to-setup-zsh-on-mac-terminal-37dj