配置经过--MAC终端神器iterm2---告别黑白
最终效果:

实现步骤
1. 下载iTerm2
安装完成后,在/bin目录下会多出一个zsh的文件。
Mac系统默认使用dash作为终端,可以使用命令修改默认使用zsh:
chsh-s /bin/zsh
zsh完美代替bash,具体区别可查看:《Zsh和Bash区别》
iterm2的原始界面

2. 替换背景图片
说明:可替换为任一你喜欢的图片


打开路径:iterm2 -> Preferences -> Profiles -> window -> Background Image
点击红框区域,可进入文件选项页,蓝色框的Mode是图片的适应方式,比如全局、拉伸等,和电脑桌面背景一样的效果。

选择一张自己喜欢的壁纸即可
可以通过Blending调节壁纸的透明度: 透明度为0的时候,背景变为纯色(黑色)
我个人比较喜欢扁平化的壁纸,喜欢的朋友可以来这里看看:
3. 安装Oh my zsh
zsh的功能极其强大,只是配置过于有点复杂,通过Oh my zsh可以很快配置zsh。
这里只做简单的配置(够用了),如需要深入了解,可以查看:《oh-my-zsh,让你的终端从未这么爽过》
安装方法有两种,可以使用curl或wget,看自己环境或喜好:
# curl 安装方式
sh-c"$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
$ sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
# wget方式(需要提前安装wget)
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)-O -)"
oh-my-zsh开源地址:《oh-my-zsh》
4. 安装PowerLine
首先先安装pip命令,安装过的可以不用安装,pip安装失败,可以选中安装pip3:
sudo easy_install pip
pip是python的一个维护命令
安装powerline:
pip install powerline-status --user 或者 pip3 install powerline-status --user
5. 安装PowerFonts
在常用的位置新建一个文件夹,如:~/Desktop/OpenSource/,不喜欢桌面放文件的可以创建新的文件夹~/iterm2-theme-OpenSource/。其中~/表示目录/User/username,比如我的就是/User/zhang**
在OpenSource文件夹下下载PorweFonts:
# git clone(这条不复制)
git clone https://github.com/powerline/fonts.git --depth=1# cd to folder(这条不复制)
cd fonts
# run install shell(这条不复制)
./install.sh
执行结果如下:

安装好字体库之后,我们来设置iTerm2的字体,具体的操作是:
iTerm2 -> Preferences -> Profiles -> Text
在Font区域选中Change Font,然后找到Meslo LG字体。

6. 安装配色方案(可跳过)
说明:这里的配色方案指的是背景的颜色,自己试试体会一下。
在OpenSource目录下执行git clone命令:
git clone https://github.com/altercation/solarized
cd solarized/iterm2-colors-solarized/
open .
在打开的finder窗口中,双击Solarized Dark.itermcolors和Solarized Light.itermcolors即可安装明暗两种配色:

再次进入iTerm2 -> Preferences -> Profiles -> Colors -> Color Presets中根据个人喜好选择.
7. 安装主题
说明:这个主题指的就是下图这个样子。

在OpenSource目录下执行git clone命令:
git clone https://github.com/fcamblor/oh-my-zsh-agnoster-fcamblor.git
cd oh-my-zsh-agnoster-fcamblor/
./install
执行上面的命令会将主题拷贝到oh my zsh的themes.
执行命令打开zshrc配置文件,将ZSH_THEME后面的字段改为agnoster
vi ~/.zshrc

我这里简单说一下vim的一些操作命令,不熟悉的可以看看:
键盘i: 进入可编辑模式,最下面显示-- INSERT --

键盘esc: 退出编辑模式
shift + : : 执行命令操作
输入wq: 保存当前更改。如果仅仅退出不保存,可以输入q
此时source ~/.zshrc或command+Q配置文件后,iTerm2变了模样:
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/12.png
8. 安装高亮插件
说明:高亮插件指的是这种效果:

这是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,我们需要把高亮插件也加上:
plugins=(
git
zsh-autosuggestions
)
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/13.png
请务必保证插件顺序,zsh-syntax-highlighting必须在最后一个。
然后在文件的最后一行添加:
source ~/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
按一下esc调出vi命令,输入:wq保存并退出vi模式。
执行命令使刚才的修改生效:
source ~/.zshrc 或 command+Q退出
所有配置至此结束。下面提供另外的功能
9. 可选择、命令补全
跟代码高亮的安装方式一样,这也是一个zsh的插件,叫做zsh-autosuggestion,用于命令建议和补全。
cd ~/.oh-my-zsh/custom/plugins/
git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc
找到plugins,加上这个插件即可:
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/15.png
插件效果:

https://raw.githubusercontent.com/sirius1024/pubimgs/master/blogs/iterm2/16.png
使用方法,点击键盘下一页使光标跳至补全内容最后,然后回车即可。
有同学说补全命令的字体不太清晰,与背景颜色太过相近,其实可以自己调整一下字体颜色。
Preferences -> Profiles -> Colors 中有Foreground是标准字体颜色,ANSI Colors中Bright的第一个是补全的字体颜色。
补充隐藏用户名和主机名:
参考2:https://www.jianshu.com/p/ba08713c2b19
九、iTerm2 隐藏用户名和主机名
有时候我们的用户名和主机名太长,终端显示的时候会很不好看,我们可以手动去除。
编辑vim ~/.zshrc文件,增加DEFAULT_USER="username"配置.
比如:我的电脑用户名为zhang**,则DEFAULT_USER="zhang**"

我们可以通过whoami命令,查看当前用户

可能遇到的问题:
如果安装后出现这种乱码的话:

参考3:https://jingyan.baidu.com/article/219f4bf7bacc2dde442d381d.html参考这个,改变字体,如下:
重启终端iterm2 ,发现显示乱码,是因为没有安装字体,下面开始介绍字体安装

执行git clone git@github.com:supermarin/powerline-fonts.git #,命令替换为下面这个命令,进行下载字体
git clone https://github.com/supermarin/powerline-fonts.git

下载完成后打开文件目录,找到/Monaco/Monaco for Powerline.otf该文件,然后双击打开(要以字体册方式打开)


弹出安装字体的对话框,点击安装即可

安装完成后字体册,用户字体多了一个新的字体,如果要卸载点击移除即可

字体安装了但是并没有配置进iterm2终端,点击终端的设置preferences

然后找到profilers菜单,在点击text,再点击change font

找到刚刚安装的字体,然后选中,关闭退出即可

然后发现终端已经有符号了,而且不乱码了

另外更换字体时去掉下图的这个勾选:

去掉显示就对了:

据说使用zsh对应的Git命令都可以简单很多。快去开发吧。祝配置顺利。
网友评论