iTerm2 + Oh My Zsh 打造温馨终端体验

写在前面

最终效果图:html

ImageInitIterm

本文严重抄袭自:https://www.jianshu.com/p/7de...git

因排版和原文中的一些bug,参照搜索引擎和原文有了本篇文章。github

由于powerline以及homebrew均须要安装command line tool,网络条件优越的同窗在执行本文下面内容以前,能够先安装XCode并打开运行一次(会初始化安装components),省去之后在iterm2中的等待时间。shell

另外,git也是必要的,各位能够自行下载安装,除了网络没有任何坑:xcode

https://git-scm.combash

介于此,本文默认各位同窗已经安装了git环境和xcode(command line tools),遇到提示找不到git命令或须要安装command line tool的地方,文中再也不赘述了。网络

下载iTerm2

能够直接去官网下载:https://www.iterm2.com/curl

安装完成后,在/bin目录下会多出一个zsh的文件。字体

Mac系统默认使用dash做为终端,可使用命令修改默认使用zsh:搜索引擎

chsh -s /bin/zsh

若是想修改回默认dash,一样使用chsh命令便可:

chsh -s /bin/bash

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

ImageInitIterm

安装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 -)"

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

ImageInitIterm

oh-my-zsh开源地址:https://github.com/robbyrusse...

安装PowerLine

powerline官网:http://powerline.readthedocs....

安装powerline的方式依然简单,也只须要一条命令:

pip install powerline-status --user

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

ImageInitIterm

使用命令安装pip便可:

sudo easy_install pip

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

ImageInitIterm

安装PowerFonts

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

在你习惯的位置新建一个文件夹,如:~/Desktop/OpenSource/

ImageInitIterm

在此文件夹下执行git clone命令:

# git clone
git clone https://github.com/powerline/fonts.git --depth=1
# cd to folder
cd fonts
# run install shell
./install.sh

执行结果以下:

ImageInitIterm

安装好字体库以后,咱们来设置iTerm2的字体,具体的操做是iTerm2 -> Preferences -> Profiles -> Text,在Font区域选中Change Font,而后找到Meslo LG字体。有L、M、S可选,看我的喜爱:

ImageInitIterm

安装配色方案

配色方案在使用VIM或Colorful Log时会变得很是有用,同时界面也不会一片黑绿同样死板。

一样使用git clone的方式下载源码进行安装:

cd ~/Desktop/OpenSource
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .

在打开的finder窗口中,双击Solarized Dark.itermcolors和Solarized Light.itermcolors便可安装明暗两种配色:

ImageInitIterm

再次进入iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中根据我的喜爱选择这两种配色中的一种便可:

ImageInitIterm

安装主题

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

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

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

ImageInitIterm

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

vi ~/.zshrc

ImageInitIterm

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

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

ImageInitIterm

安装高亮插件

这是oh my zsh的一个插件,安装方式与theme大同小异:

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git
vi ~/.zshrc

这时咱们再次打开zshrc文件进行编辑。找到plugins,此时plugins中应该已经有了git,咱们须要把高亮插件也加上:

ImageInitIterm

请务必保证插件顺序,zsh-syntax-highlighting必须在最后一个。

而后在文件的最后一行添加:source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

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

执行命令使刚才的修改生效:

source ~/.zshrc

至此大功告成,请看最终效果图:

ImageInitIterm

背景图片取自微软Surface Studio的4K壁纸(将近12MB大小),很是漂亮,须要的能够自取:

连接: https://pan.baidu.com/s/17zGm...
提取码: hg67

更换背景图片方式:iTerm2 -> Preferences -> Profiles -> Window -> BackGround Image勾选图片便可。

可选择、命令补全

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

cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc

找到plugins,加上这个插件便可:

ImageInitIterm

插件效果:

ImageInitIterm

Github:https://github.com/sirius1024...

喜欢请Star哦

相关文章
相关标签/搜索