Mac配置-iTerm2和oh-my-zsh

687 阅读1分钟

前置知识

  1. iterm2是什么
  • iTerm2是MAC下最好的终端工具,可以平替Terminal。
  1. oh-my-zsh是什么
  • zshbashcsh等都是常用的shell,一般电脑默认bash。有多种shell的原因是Linux由多个组织机构开发,不同的组织机构开发不同的功能类似的shell。
  • zsh是在bash(macOS的默认shell)之上构建的Unix shell,并进行了大量改进。但配置过于复杂,起初只有极客才在用。后来,有个大佬Robby Russel在GitHub上制作了一个配置文件oh-my-zsh,这是目前为止最流行的zsh配置。
  • 结论:oh-my-zsh是zsh的配置文件,因为配置起来很方便,所以现在几乎成为标配。

安装iTerm2

  1. 你可以直接从官网下载iTerm2
  2. 把iTerm2设为默认,找到选项:iTerm2 -> Make ITerm2 Default Term

安装oh-my-zsh

  1. curl
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
  1. 配置主题
  • 官方收集了一些主题(不再收录新主题),你可以访问 主题&&截图 页面查看并选取。 这里以agnoster为例说明。
  • 编辑~/.zshrc文件,修改ZSH_THEME配置:
ZSH_THEME="agnoster"
# 主题介绍请访问 https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster

大部分主题都用到了 Powerline Fonts

下载好ttf文件,双击即可完成安装。

  • 选择字体 然后打开iTerm -> Preferences -> Profiles -> Text -> Change Font,选择Meslo LG S Regular for Powerline

重新打开iTerm2就能看到效果。

  1. 功能增强
  • zsh-autosuggestions,命令自动补全功能。

克隆代码到$ZSH_CUSTOM/plugins(默认位于~/.oh-my-zsh/custom/plugins

git clone https://gitee.com/imirror/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
  • zsh-syntax-highlighting,语法高亮。 克隆代码到$ZSH_CUSTOM/plugins(默认位于~/.oh-my-zsh/custom/plugins
git clone https://gitee.com/imirror/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
  • Oh My Zsh配置启用插件 打开~/.zshrc,找到plugins,追加zsh-autosuggestions

git为默认配置。

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
  • 最后执行source ~/.zshrc生效。