iTerm2 + Oh My Zsh 打造舒适终端体验

2018-07-30  本文已影响0人  坏坏的饭团

本文严重抄袭自:

  1. https://www.jianshu.com/p/7de00c73a2bb
  2. https://github.com/sirius1024/iterm2-with-oh-my-zsh

下载安装 iTerm2

在这之前我们已经安装了 Homebrew,如果未安装请移步

$ brew cask install iterm2

Mac系统默认使用dash作为终端,可以使用命令修改默认使用zsh:

$ chsh -s /bin/zsh

如果想修改回默认dash,同样使用chsh命令即可:

$ chsh -s /bin/bash

OK,这就是iTerm2初始的样子,下面我们来美化它,让它变得更好用!


原始 iTerm2

安装 Oh My Zsh

安装方法有两种,可以使用curl或wget,看自己环境或喜好:

# curl 安装方式
$ sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# wget 安装方式
$ sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

安装命令和安装完成后的截图:


Oh My Zsh

安装 Powerline

$ pip install powerline-status --user

没有安装 pip 的同学可能会碰到 zsh: command not found: pip。


未安装 pip 截图

安装 pip 即可:

$ sudo easy_install pip

安装后再次执行安装 powerline 的命令即可。


powerline 安装成功

安装 PowerFonts

安装字体库需要首先将项目git clone至本地,然后执行源码中的install.sh

# clone
$ git clone https://github.com/powerline/fonts.git --depth=1
# install
$ cd fonts
./install.sh
# clean-up a bit
$ cd ..
$ rm -rf fonts

安装完成后提示所有字体均已下载到 /Users/用户名/Library/Fonts 路径下

设置 iTerm 2 字体

安装完字体库之后,把iTerm 2的设置里的 Profile 中的 Text 选项卡中里的Regular FontNon-ASCII Font 的字体都设置成 Powerline 的字体,具体的操作是iTerm2 -> Preferences -> Profiles -> Text,在Font区域选中Change Font,然后找到Meslo LG字体。

设置 iTerm 2 字体

安装配色方案

再次进入 iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets 中根据个人喜好选择这两种配色中的一种即可。我选择的是 Solarized Dark

安装 agnoster 主题

下载agnoster主题,执行脚本安装:

$ git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
$ cd oh-my-zsh-agnoster-fcamblor/
$ ./install

执行上面的命令会将主题拷贝到oh my zsh的themes中:


安装 agnoster 主题

拷贝完成后,执行命令打开zshrc配置文件,将ZSH_THEME后面的字段改为agnoster。

$ vi ~/.zshrc
设置 agnoster 主题

修改完成后按一下esc调出vi命令,输入:wq保存并退出vi模式。

此时command+Q或source配置文件后,iTerm2变了模样:

iTerm 2

安装指令高亮效果——zsh-syntax-highlighting

指令高亮效果作用是当用户输入正确命令时指令会绿色高亮,错误时命令红色高亮

$ brew install zsh-syntax-highlighting

然后编辑 ~/.zshrc ,在末尾添加 source /usr/local/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

# 编辑 .zshrc
$ vi ~/.zshrc
# 重新加载 .zshrc
$ source ~/.zshrc

安装命令建议和补全——zsh-syntax-highlighting

跟代码高亮的安装方式一样,这也是一个zsh的插件,叫做zsh-autosuggestion,用于命令建议和补全。

$ brew install zsh-autosuggestions

然后编辑 ~/.zshrc ,在末尾添加 source /usr/local/share/zsh-autosuggestions/zsh-autosuggestions.zsh

# 编辑 .zshrc
$ vi ~/.zshrc
# 重新加载 .zshrc
$ source ~/.zshrc
上一篇下一篇

猜你喜欢

热点阅读