前置知识
- iterm2是什么
- iTerm2是MAC下最好的终端工具,可以平替Terminal。
- oh-my-zsh是什么
zsh、bash、csh等都是常用的shell,一般电脑默认bash。有多种shell的原因是Linux由多个组织机构开发,不同的组织机构开发不同的功能类似的shell。zsh是在bash(macOS的默认shell)之上构建的Unix shell,并进行了大量改进。但配置过于复杂,起初只有极客才在用。后来,有个大佬Robby Russel在GitHub上制作了一个配置文件oh-my-zsh,这是目前为止最流行的zsh配置。- 结论:oh-my-zsh是zsh的配置文件,因为配置起来很方便,所以现在几乎成为标配。
安装iTerm2
- 你可以直接从官网下载
iTerm2。 - 把iTerm2设为默认,找到选项:
iTerm2 -> Make ITerm2 Default Term
安装oh-my-zsh
- curl
sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)"
- 配置主题
- 官方收集了一些主题(不再收录新主题),你可以访问 主题&&截图 页面查看并选取。
这里以
agnoster为例说明。 - 编辑
~/.zshrc文件,修改ZSH_THEME配置:
ZSH_THEME="agnoster"
# 主题介绍请访问 https://github.com/ohmyzsh/ohmyzsh/wiki/Themes#agnoster
- 安装字体
agnoster还需要额外安装字体 Meslo for Powerline
大部分主题都用到了 Powerline Fonts
下载好ttf文件,双击即可完成安装。
- 选择字体
然后打开
iTerm -> Preferences -> Profiles -> Text -> Change Font,选择Meslo LG S Regular for Powerline。
重新打开iTerm2就能看到效果。
- 功能增强
- 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生效。