安装 iTerm2

  1. 使用 brew 安装(推荐)

    1
    brew install iterm2
  2. 官网下载安装包安装

安装 oh-my-zsh

参考官网ohmyz有两种方式,可以根据自己的环境选择:

  1. 使用 curl

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

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

修改默认 shell

Linux 下默认的是 bash ,macOS 在 Catalina 之前的版本默认也是 bash ,后面随着 zsh 越来越流行,Catalina 版本之后 macOS 开始将 zsh 作为默认的解释器了。

  1. 查看当前用户的 shell:

    1
    echo $SHELL
  2. 如果不是 zsh 的话,使用以下命令修改为 zsh:

    1
    chsh -s /bin/zsh 	

修改主题

安装好必要的配置后,接下来就是选择一个喜欢的主题了,https://github.com/ohmyzsh/ohmyzsh/wiki/themes 这上面主题非常多,各种各样的风格都有,可以根据自己的喜好选择一个即可。

推荐一下我自己使用的主题 powerlevel10k

  1. 克隆仓库

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

  3. 主题中会有特殊的表情和符号,需要下载 [MesloLGS NF Regular.ttf](https://github.com/romkatv/powerlevel10k-media/raw/master/MesloLGS NF Regular.ttf) 字体。

  4. 选择字体,具体为 iTerm2 -> Preferences -> Profiles -> Text,在 Font 区域选中Change Font,选择刚刚安装的字体。

  5. 重启终端,根据提示进行个性化配置。

安装插件

如何安装插件

打开~/.zshrc,找到plugins=(...) 这条命令,将想要使用的插件添加到括号中,用空格分割,之后source ~/.zshrc就可以啦,注意有些插件是 zsh 自带的,有些插件需要自己安装,安装后才会生效。

插件推荐

zsh 自带插件

  1. git

    配置了 git 相关命令的 alias,例如常用的:

    1
    2
    3
    4
    5
    gaa = git add --all
    gcmsg = git commit -m
    ga = git add
    gst = git status
    gp = git push
  2. z

    在常用目录间跳转,例如 cd ~/aaa/bbb/ccc 之后,下次只需要 z ccc就能跳转到相应目录。

  3. history-substring-search

    根据前缀搜索历史命令,只需要输入命令行的前缀,之后就可以使用“上下”箭头查找历史记录。

  4. sudo

    输完命令忘记加 sudo 了?只需要双击 ESC 就好啦。

需要下载的插件

  1. zsh-syntax-highlighting

    shell 命令行高亮,没有任何理由拒绝高亮。

    安装:git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

  2. zsh-autosuggestions

    在输入命令的过程中根据历史记录提示最近匹配的命令,按 tab 键补全。

    安装:git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

  3. zsh-jinrishici

    打开终端时随机显示一句诗词,该插件需要配合 jq 一起使用 brew install jq

​ 安装:git clone https://github.com/SouthWind6510/zsh-jinrishici.git $ZSH_CUSTOM/plugins/zsh-jinrishici