ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

MAC终端神器iterm2——告别黑白

2021-04-14 10:02:45  阅读:238  来源: 互联网

标签:zsh git oh com iterm2 神器 MAC https my


<div class="oneLevelTitle">最终效果:</div> ![](https://www.icode9.com/i/l/?n=18&i=blog/1414709/201809/1414709-20180924160212667-1542960513.png)

<div class="oneLevelTitle">实现步骤</div> ### 1. 下载iTerm2 官网下载:https://www.iterm2.com/

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

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

chsh -s /bin/zsh

zsh完美代替bash,具体区别可查看:<a href="https://www.xshell.net/shell/bash_zsh.html" target="_blank">《Zsh和Bash区别》</a>

<b>iterm2的原始界面</b>

2. 替换背景图片

打开路径:iterm2 -> Preferences -> Profiles -> window -> Background Image

选择一张自己喜欢的壁纸即可

可以通过Blending调节壁纸的透明度: 透明度为0的时候,背景变为纯色(黑色)

我个人比较喜欢扁平化的壁纸,喜欢的朋友可以来这里看看:
<a href="https://www.zhihu.com/question/37811449" target="_blank">《有哪些优雅的 Windows 10 壁纸?》</a>

3. 安装Oh my zsh

zsh的功能极其强大,只是配置过于复杂,通过Oh my zsh可以很快配置zsh。

这里只做简单的配置,如需要深入了解,可以查看:<a href="https://www.jianshu.com/p/d194d29e488c?open_source=weibo_search" target="_blank">《oh-my-zsh,让你的终端从未这么爽过》</a>

安装方法有两种,可以使用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开源地址:<a href="https://github.com/robbyrussell/oh-my-zsh" target="_blank">《oh-my-zsh》</a>

4. 安装PowerLine

首先先安装pip命令:

sudo easy_install pip

pip是python的一个维护命令

安装powerline:

pip install powerline-status --user

5. 安装PowerFonts

在常用的位置新建一个文件夹,如:~/Desktop/OpenSource/

在<b>OpenSource</b>文件夹下下载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配置文件,<font color="red">将ZSH_THEME后面的字段改为agnoster</font>

vi ~/.zshrc

我这里简单说一下vim的一些操作命令,不熟悉的可以看看:

<b>键盘i</b>: 进入可编辑模式,最下面显示-- INSERT --

<b>键盘esc</b>: 退出编辑模式

<b>shift + :</b> : 执行命令操作

<b>输入wq</b>: 保存当前更改。如果仅仅退出不保存,可以输入q

此时command+Q或source配置文件后,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,我们需要把高亮插件也加上:

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

所有配置至此结束。下面提供另外的功能

9. 可选择、命令补全

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

cd ~/.oh-my-zsh/custom/plugins/

git clone https://github.com/zsh-users/zsh-autosuggestions
vi ~/.zshrc

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

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的第一个是补全的字体颜色。

标签:zsh,git,oh,com,iterm2,神器,MAC,https,my
来源: https://blog.51cto.com/u_7605937/2704825

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有