发布于 2026-01-05 10 阅读
0

终端设置 - 让你的 Mac 终端更强大

终端设置 - 让你的 Mac 终端更强大

我最近安装了新的MacBook并设置了终端。在这里,我将向您展示如何在您的MacBook上执行相同的操作。

最终结果

这是基于性能卓越的powerlevel10k 的最终成果。易于配置和修改,并针对开发人员进行了优化。

您会注意到顶部工具栏(CPU、内存、网络),以便随时了解硬件使用情况。

Mac终端

先决条件

安装Homebrew



/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"


Enter fullscreen mode Exit fullscreen mode

安装iTerm2和 git



brew install --cask iterm2
brew install git


Enter fullscreen mode Exit fullscreen mode

安装Oh My Zsh



$ sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"


Enter fullscreen mode Exit fullscreen mode

主题安装

我选择了powerlevel10k,这可能是你能选择的最佳且最灵活的主题之一。
只需重新运行安装命令,即可轻松更改终端布局。

开始安装MesloLGS 字体



MesloLGS NF Regular.ttf
MesloLGS NF Bold.ttf
MesloLGS NF Italic.ttf
MesloLGS NF Bold Italic.ttf


Enter fullscreen mode Exit fullscreen mode

然后安装powerlevel10k本身



git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k


Enter fullscreen mode Exit fullscreen mode

设置~/.zshrcZSH 主题:



ZSH_THEME="powerlevel10k/powerlevel10k" in ~/.zshrc.


Enter fullscreen mode Exit fullscreen mode

您至少可能需要配置以下两个 ZSH 插件:

zsh-syntax-highlighting - 类似 Fish shell 的 Zsh 语法高亮功能。它能让上面的别名/命令显示为绿色。如果显示为绿色,则表示已安装!
zsh-autosuggestions - 类似 Fish 的 Zsh 自动建议功能。输入时会显示上次匹配命令的预览。按右键即可使用。

设置~/.zshrc要使用的 ZSH 插件:



plugins=(
  git
  zsh-syntax-highlighting
  zsh-autosuggestions
)


Enter fullscreen mode Exit fullscreen mode

使用 Zsh重启终端

现在你可以运行了



p10k configure


Enter fullscreen mode Exit fullscreen mode

如果字体显示有问题,请检查是否选择了 MesloLGS 字体
Open iTerm2 → Preferences → Profiles → Text and set Font to MesloLGS NF

最后,如果您想包含现有的 bash 别名和函数:在导出 ZSH之前,
在源 bash_profile 文件中。~/.zshrc



source ~/.bash_profile

Enter fullscreen mode Exit fullscreen mode




添加工具栏

工具栏

打开你的iterm2 > Profile > Session > Status bar enabled
iTerm2 配置

选择您的组件。
iTerm2 状态栏小部件

完成的!

我希望这篇简短的教程能帮助你改进设置。它显然并不完整,但足够简单易懂,可以让你继续学习。

文章来源:https://dev.to/alagrede/terminal-setup-make-your-mac-terminal-awesome-4ecc