Configuration and beautification of iTerm2

This is the second day of my participation in the August Update Challenge. For details of the event, please check: August Update Challenge

foreword

iTerm2 is a replacement for the default terminal, and it is also the best terminal tool under the Mac system. It combines beauty and efficiency.

I recently got a new MacBook Pro and needed to reinstall the common software on the computer. It took me a lot of time to DIY ITerm2 to my liking. In order to facilitate the next configuration, I specially wrote this article for recording.

Download link for iTerm2: iterm2.com/

Configuration of iTerm2

1. Set the default shell to zsh

View a list of all shells in the system

cat /etc/shells
复制代码

Set the default shell to zsh, which has more functions and will be easier to use.

chsh -s /bin/zsh
复制代码

2. Install oh-my-zsh

oh-my-zsh is a community-driven command line tool. It is based on the zsh command line, providing theme configuration and plug-in mechanism, which greatly improves the playability (usability). Its Github address is: github.com/robbyrussel…

We can install using curl:

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
复制代码

3. Automatic prompts for configuration commands

Here we use the zsh-autosuggestions plug-in, which allows the terminal to prompt us for the commands we may enter next, and press the right button to complete them, improving the efficiency of our work.

First, we clone the repository to the ~/.oh-my-zsh/custom/pluginsdirectory

git clone git://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
复制代码

Then, vim ~/.zshrcopen the file with and find the plugin settings in it, the default is plugins=(git), we will modify it to

plugins=(zsh-autosuggestions git)
复制代码

Finally, you need to restart the terminal for it to take effect.

4. Install HomeBrew

Install the HomeBrew package management tool to facilitate subsequent installation of various software packages.

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
复制代码

Beautification of iTerm2

1. Set the zsh theme

We can open the zsh configuration file through the vim ~/.zshrccommand , modify ZSH_THEMEthe value of the field in it, and modify the theme.

大家可以在 github.com/ohmyzsh/ohm… 链接中,选择自己喜欢的主题。

我选择的主题的是 crcandy,因为它选择的信息比较全,而且它不依赖其他的特殊字体,可以在不同的终端下正常显示。

ZSH_THEME="crcandy"
复制代码

该主题的显示信息如下(忽略配色):

insert image description here

2. 设置配色方案

在 iTerm2 中,按照 iTerm2 -> Preferences -> Profiles -> Color 进行点击,在右下角的 Color Presets... 中选择配色方案,这里我选择 Solarized Dark。

insert image description here

之后,我们再进行一些微调,让显示的色彩变得更加美观一些。

insert image description here

3. 设置语法高亮

语法高亮效果需要 zsh-syntax-highlighting 插件支持,我们可以用 HomeBrew 进行下载:

brew install zsh-syntax-highlighting
复制代码

命令执行完后,我们记录一下插件安装成功后的路径。然后用 vim ~/.zshrc 打开 zsh 的配置文件,在其末尾添加:

source /usr/local/Cellar/zsh-syntax-highlighting/0.7.1/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
复制代码

PS:在 Vim 中,用 shift + g 可以直接跳转到最后一行。

最后,还要执行下面命令,让配置生效。

source ~/.zshrc
复制代码

4. 调整 Status Bar

在 Preferences -> Profiles -> Session 底部,勾选上 Status bar enabled,开启导航栏。

点击右边的 Configure Status Bar 按钮可设置 Status Bar 显示的内容,只要将 Menu 里面的内容拖拽到下面的 Active Components 区域即添加到 Status Bar 中,下面是我的设置(仅供参考):

insert image description here

Next, we go to Preferences -> Appearance -> General, set the Theme to Minimal and the Status bar location to Bottom.

insert image description here

Subsequent use optimization

1. Fix oh-my-zsh warning message

We found that every time we open iTerm2, there is a warning message of oh-my-zsh, which affects our mood. I found online there are two solutions below.

Option 1: Follow the installation prompts to modify the permissions of the corresponding directory, and execute the following command on the console

chmod 755 /usr/local/share/zsh

chmod 755 /usr/local/share/zsh/site-functions
复制代码

Option 2: Add the following content to the ~/.zshrcfile

ZSH_DISABLE_COMPFIX=true
复制代码

2. Turn off daily reminders for iTerm2

Preferences > Advanced > 搜索 Tip of the Day > Disable the Tip of the Day 改为 Yes

insert image description here

References

Guess you like

Origin juejin.im/post/6994453537690222599