macOS终端美化

随着官方版本的更新,在你看到这篇文章时,有些配置可能已经过时。请以官方文档为准。

安装 Oh My ZSH

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

禁用自动更新

1
zstyle ':omz:update' mode disabled 

安装插件

zsh-syntax-highlighting

  • 克隆插件到本地
    1
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • 修改 ~/.zshrc 文件,添加插件
    1
    plugins=( [plugins...] zsh-syntax-highlighting)
  • 使修改生效
    1
    source ~/.zshrc

zsh-autosuggestions

  • 克隆插件到本地
    1
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  • 修改 ~/.zshrc 文件,添加插件
    1
    2
    3
    4
    plugins=( 
    # other plugins...
    zsh-autosuggestions
    )
  • 使修改生效
    1
    source ~/.zshrc

sublime

  • 修改 ~/.zshrc 文件,添加插件
    1
    plugins=(... sublime)
  • 使修改生效
    1
    source ~/.zshrc

powerlevel10k主题

  • 克隆到本地

    1
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
  • 修改主题配置 ~/.zshrc:

    1
    2
    ZSH_THEME="powerlevel10k/powerlevel10k"
    POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon dir vcs) # 配置左侧图标
  • 下载字体文件
    MesloLGS NF Regular.ttf
    MesloLGS NF Bold.ttf
    MesloLGS NF Italic.ttf
    MesloLGS NF Bold Italic.ttf

  • 双击下载好的文件完成安装

  • 配置终端字体为MesloLGS NF

  • 使主题修改生效, 在执行这个之前需要配置好字体。不然在powerlevel10k引导配置时,图标显示会乱码。

    1
    source ~/.zshrc

修改终端配色iTerm2-Color-Schemes

  • 克隆仓库到本地
    1
    git clone https://github.com/mbadolato/iTerm2-Color-Schemes.git
  • 导入iTerm2-Color-Schemes主题文件, Mac 终端选择 terminal 文件夹下的文件。

参考

ohmyzsh
powerlevel10k
iTerm2-Color-Schemes
10 个 Terminal 主题,让你的 macOS 终端更好看