起因

因工作需要,总要初始化电脑,俗称装机,而绝大部分的配置项,一旦配置好了就很少再动了,此篇记录我最喜欢的终端操作组合:iTerm2 + zsh + on my zsh + brew

Zsh

Zsh应该是在MacOS 10版本自带了,MacOS 10以上的版本不需要安装了,直接开箱即用。

Oh My Zsh

Zsh 的配置项过于复杂,开源项目Oh My Zsh 解决了这一问题,仅通过简单的配置,即可享用Zsh丰富的功能。

安装Oh My Zsh

通过curl

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

通过wget

1
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"

安装brew

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

Oh My Zsh主题—powerlevel9k

  1. 克隆powerlevel9k仓库到oh my zsh的custom/themes 目录

    1
    git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k
  2. ~/.zshrc 设置主题

    1
    ZSH_THEME="powerlevel9k/powerlevel9k"
  3. 别忘了

    1
    source ~/.zshrc

安装支持powerlevel9k的字体Powerline fonts

1
2
3
4
5
6
7
8
# clone
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit
cd ..
rm -rf fonts

安装iTerm2

在安装了brew的前提下,安装很简单

1
brew install --cask iterm2

并安装font-hack-nerd-font

1
2
brew tap homebrew/cask-fonts #将字体库添加到brew安装中
brew install --cask font-hack-nerd-font

安装iTerm2主题

1
git clone https://github.com/dracula/iterm.git

安装Dracula iTerm2主题

在iTerm2中设置字体

  1. 需要在iTerm2的Preference -> Profiles -> Text -> Font 中设置字体,比如这样

    iShot2022-04-03 06.59.14

  2. 并在~/.zshrc 中声明

    1
    POWERLEVEL9K_MODE='nerdfont-complete'

Zsh中的插件

我只用到了zsh-syntax-highlighting高亮插件,最好的方式是通过plugin manager安装

  1. 克隆到本地

    1
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  2. ~/.zshrc中添加

    1
    plugins=( [plugins...] zsh-syntax-highlighting)
  3. 别忘了

    1
    source ~/.zshrc

这里是参考

~/.zshrc中的配置项

powerlevel9k 中有一个Show Off Your Config · Powerlevel9k/powerlevel9k Wiki · GitHub ,里面分享了很多帅酷的配置和截图。

我喜欢追求一个简洁和美观的均衡,下面是我的配置效果。

zshrc_config

当然也把我的配置分享在GitHub了,链接在这里