Mac配置iterm2+oh my zsh

//Mac配置iterm2+oh my zsh

#Mac iTerm2 + Oh My Zsh 打造舒适终端体验
##最终效果预览
95
因为powerline以及homebrew均需要安装command line tool,网络条件优越的同学在执行本文下面内容之前,可以先安装XCode并打开运行一次(会初始化安装components),省去以后在iterm2中的等待时间。

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

https://git-scm.com

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

下载iTerm2

可以直接去官网下载:https://www.iterm2.com/

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

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


chsh -s /bin/zsh

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


chsh -s /bin/bash

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

1

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

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

2

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

安装PowerLine

powerline官网:http://powerline.readthedocs.io/en/latest/installation.html

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


pip install powerline-status --user

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

3

使用命令安装pip即可:


sudo easy_install pip

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

4

安装PowerFonts

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

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

5

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


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

执行结果如下:

6

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

7

安装配色方案

配色方案在使用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即可安装明暗两种配色:

8

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

9

安装主题

下载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中:

91

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


vi ~/.zshrc

92

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

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

93

安装高亮插件

这是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,我们需要把高亮插件也加上:

94

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

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

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

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


source ~/.zshrc

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

95

背景图片取自微软Surface Studio的4K壁纸(将近12MB大小),非常漂亮.
更换背景图片方式: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,加上这个插件即可:
96

插件效果:
97

7 评论

  1. GeorgeCecow 2019年5月21日 在 下午9:48 -回复

    Dearest in mind,
    I would like to introduce myself for the first time. My name is Barrister David Gómez González, the personal lawyer to my late client.
    He worked as a private businessman in the international field. In 2012, my client succumbed to an unfortunate car accident. My client was single and childless.
    He left a fortune worth $24,500,000.00 Dollars in a bank in Spain. The bank sent me message that I have to introduce a beneficiary or the money in their bank will be confiscate. My purpose of contacting you is to make you the Next of Kin.
    My late client left no will, I as his personal lawyer, was commissioned by the Spanish Bank to search for relatives to whom the money left behind could be paid by my deceased client. I have been looking for his relatives for the past 3 months continuously without success. Now I explain why I need your support, I have decided to make a citizen of the same country with my late client the Next of Kin.
    I hereby ask you if you give me your consent to present you as the next of kin to my deceased client to the Spanish Bank as the beneficiary. I would like to point out that you will receive 45% of the share of this money, 45% then I would be entitled to, 10% percent will be donated to charitable organizations.
    If you are interested, please contact me at my private contact details by Tel: 0034-604-284-281, Fax: 0034-911-881-353, Email: ddggabogados@mail.com
    I am waiting for your answer
    Best regards,
    Lawyer: – David Gómez González

  2. Livechatlip 2019年5月17日 在 下午3:35 -回复

    Wow, fantastic blog layout! How lengthy have you ever been blogging for? you make running a blog [url=https://livexporno.com]live free porn[/url] glance easy. The total glance of your website is magnificent, let alone the content material!

  3. eisnor 2019年4月21日 在 下午2:05 -回复

    Good day! feleti.cn

    We propose

    Sending your message through the Contact us form which can be found on the sites in the Communication partition. Feedback forms are filled in by our software and the captcha is solved. The advantage of this method is that messages sent through feedback forms are whitelisted. This method increases the probability that your message will be open. Mailing is done in the same way as you received this message.
    Your commercial proposal will be seen by millions of site administrators and those who have access to the sites!

    The cost of sending 1 million messages is $ 49 instead of $ 99. (you can select any country or country domain)
    All USA – (10 million messages sent) – $399 instead of $699
    All Europe (7 million messages sent)- $ 299 instead of $599
    All sites in the world (25 million messages sent) – $499 instead of $999

    Discounts are valid until April 25.
    Feedback and warranty!
    Delivery report!
    In the process of sending messages we don’t break the rules GDRP.

    This message is automatically generated to use our contacts for communication.

    Contact us.
    Telegram – @FeedbackFormEU
    Skype – FeedbackForm2019
    Email – FeedbackForm@make-success.com

    All the best

  4. Charlescug 2019年4月4日 在 上午6:54 -回复

    [url=http://albendazole.run/]albendazole[/url]

  5. TadalafilGlori 2019年3月27日 在 上午1:50 -回复

    tadalafil generic tadalafil when to take

  6. MatBleany 2019年3月23日 在 下午3:20 -回复

    Buy Xenical Online Surdosage Levitra Lamisil 250 Mg Online [url=http://arealot.com]buy zoloft uk[/url] Generic Secure Ordering Zentel With Overnight Delivery Medicine Store

  7. buy generic cialis online 2019年3月22日 在 上午7:15 -回复

    Hey I know this is off topic but I was wondering if you knew of any widgets I could add to my blog that automatically tweet my
    newest twitter updates. I’ve been looking for a plug-in like this for quite some time and was hoping maybe you would have some experience with something like this.
    Please let me know if you run into anything. I truly enjoy reading your blog and I look forward to your new updates.

发表评论