Mac os spend macOS Catalina ahead of Shell Oh My Zsh Configuration Guide

In the early convening of the WWDC 2019, Apple released the next generation macOS - macOS Catalina. In addition to self-evident updated cut new music and TV app, support iPad as an external monitor, etc., macOS Catalina also brought a major change to professional users - Zsh will replace Bash, the default operating system of Shell .

Apple did not just make a comment on this change, but The Verge's credentials speculated that this may be related to GPLv3 peace talks. Bash 3.2 version macOS current application based on GPLv2 peace talks, but has been moved to the new version of Bash GPLv3 peace talks. GPLv3 peace talks with tighter restrictions on the promise of big companies such as Apple, which Apple might no longer be the default Bash Shell's sake.

It compared Bash, Zsh also have a lot more powerful in effect: more intelligent auto-completion, command options reminders, and more rich themes, and so on. In this fall to experience the macOS Catalina official version of the past, we can first macOS default Shell switched to zsh, familiarize yourself with the new Shell effect.

The goal of this paper, that is to help you create a visually appealing, easy to use Zsh terminal.

A beautiful and powerful terminal

e4aadc17f42643d1851d9dcd9e7fac7c.png

Zsh 与 Oh My Zsh

Zsh body has to grow and efficacy, but because of its complex configuration, for the average user and not applicable. However, a revenue of names appears to break this terrain - that is, it is the protagonist of this article: Oh My Zsh. With Oh My Zsh, you only need to be placed extremely simple configuration, you spend Zsh, and enjoy a lot of cool effects, let's start the formal process of resettlement.

Resettlement Oh My Zsh

macOS Mojave ever comes Zsh, so we simply placed Oh My Zsh. Placement course is very simple, open a terminal, you can execute command line:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

在安置历程中会提醒 Do you want to change your default shell to zsh? [Y/n](是否将默认 Shell 切换到 Zsh),按下 Y 并回车即可。随后会提醒 Password for xxx,输入你的用户密码并回车即可。当你瞥见大大的 Oh my zsh 标志时就表示 Oh My Zsh 曾经安置胜利了。

显示「Oh my zsh」表示安置胜利

5d17aa48bcc54deaade65637d93e1280.png

根基配置

安置好 Oh My Zsh 后,应用以下号令翻开 Zsh 的配置文件:

vim ~/.zshrc

在 vim 编纂器下,你可以应用偏向键挪动光标,按 i 进入编纂模式,编纂好后按 esc 退出编纂模式,随后输入 :wq 并回车即可留存。相关 Vim 的更多应用要领你可以参考 这篇教程。另外,Mac 下的 Vim 默认是没有显示行号 & 开启语法高亮的,你可以参考以下号令翻开行号显示 & 语法高亮:

cp /usr/share/vim/vimrc ~/.vimrc#复制 vim 配置模版

echo 'syntax on' >> ~/.vimrc#开启语法高亮

echo 'set nu!' >> ~/.vimrc#开启行号显示

Zsh 的配置文件中提供了详细的注释,你可以凭据注释点窜关联配置,满足本人的要求。比方,你想关闭 Zsh 的自动更新,则定位到 DISABLE_AUTO_UPDATE 一行,凭据前面的注释,删除行前的注释象征 # 即可。

关闭自动更新

220917a24ef74c69822f5d9c4e0a2765.png

留存退出以后,应用以下号令使 Zsh 的配置登时见效:

source ~/.zshrc

配置主题

Oh My Zsh 自带了大批主题文件。你可以执行以下号令查看自带的主题:

ls ~/.oh-my-zsh/themes

对于自带主题的样式和出现结果,你可以前往 Oh My Zsh 的 官方 Wiki 查看。

在这里,我选定应用 agnoster 作为我的主题。我们必要通过编纂 zsh 配置文件来点窜主题:

vim ~/.zshrc

定位到 ZSH_THEME 一行,将双引号中的内容点窜为本人选定的主落款即可。

点窜主落款

6685130c3a86482eaae84e2803732a7b.png

留存退出后,执行以下号令使 zsh 的配置登时见效:

source ~/.zshrc

安置 Powerline 字体

主题配置实现后,终端中却出现了乱码的字符:

乱码字符

1c58140a7b0f4b2ab5559c27706a5c76.png

这是因为我应用的 agnoster 主题中含有分外字符,必要安置 Powerline 字体支持才气平常显示。翻开终端,参考以下号令安置 Powerline 字体:

cd ~/Downloads && git clone https://github.com/powerline/fonts.git#将 Powerline 字体文件下载到「下载」文件夹中

cd fonts && ./install.sh#安置所有 Powerline 字体

cd && rm -rf ~/Downloads/fonts#删除下载的字体文件

随后,我们按 ⌘, 翻开终端偏好配置,在「形貌文件 > 文本」中更改字体。

更改字体选项

db84ba6d2d554f568367b21e291d86cd.png

在弹出的窗口当选定一款 Powerline 字体(所有可选项请参考 Powerline 的 GitHub 页面),调整一下字体大小即可。在这里我选定了 DejaVu Sans Mono for Powerline 字体(逮虾户!),大小配置为 14 磅。

我的字体配置

73a29c4e16c147568d7dc7245941a97e.png

此时回到终端,发现表示文件目次的箭头曾经可以平常显示了:

Powerline 字体可以在 agnoster 主题中平常显示

0d0de360596740ef80fe5defbe41f3a3.png

配置终端色彩计划

主题上的配置至此就差未几了,不过 macOS Mojave 默认终端的黑底白字看起来照旧有些不舒适。在这里,我们无妨应用 Solarized 配色计划来进一步粉饰终端。开始,应用以下号令下载 Solarized 配色计划:

cd ~/Downloads && git clone git://github.com/altercation/solarized.git#将配色计划下载到「下载」文件夹中

下载完毕后,我们按 ⌘, 翻开终端偏好配置,点击「形貌文件 > ⚙︎⌄ > 导入」。

导当选项

1a7325d87f62477fba7d9187080306ef.png

在弹出的窗口中,定位到 Downloads > solarized > osx-terminal.app-colors-solarized,双击 Solarized Dark ansi.terminal 导入暗色的 Solarized 配色计划。

选定下载好的 Solarized 配色计划

88b07885ae7a4e72b343fe5f89635a30.png

随后,我们在形貌文件当选中 Solarized Dark ansi,点击「默认」将其设为默认配色计划;别忘了把字体改成 Powerline 字体并调整大小。

别忘记改字体

5d85943051704ad7b849ed6be8e11d0d.png

配色细节点窜

重启一下终端,到这里,我们漂亮的终端曾经根基实现了,不过当今的配色让人有些看不清字:

有些看不清字

a6854d179ef64781af017273215d183f.png

重度强迫症的我肯定不行接受。是以我们按 ⌘, 翻开终端偏好配置,点击「形貌文件 > Solarized Dark ansi」,对配色进行进一步的自定义。单击你想要更改的色彩,在弹出的小窗口中点选拾色器(像吸管同样的东西)。

拾色器

b4f178a1b2664b63bec91a92b23b2def.png

随后,你可以参考下图把色彩一项一项吸过去。这里我的配置概括了 iTerm 2 的配色和个人的少量点窜。

配色计划参考

ff6a5ee2518843939eb8685d736b26ce.png

另有一项让我不爽的地方 —— 文件目次前那个长长的 demo@Stevens-MacBook-Pro。通过点窜主题配置文件,我们就能去掉它。应用以下号令编纂 agnoster 主题的配置文件:

vim ~/.oh-my-zsh/themes/agnoster.zsh-theme

定位到以下内容:

# Context: user@hostname (who am I and where am I)

prompt_context() {

if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then

prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m"

fi

}

在 prompt_segment black default "%(!.%{%F{yellow}%}.)%n@%m" 前面加一个注释象征 #,留存退出,执行 source ~/.zshrc 使配置登时见效即可。

配置插件

Oh My Zsh 支持很多壮大的插件,可以实现语法高亮、号令自动补全等功效。你可以执行以下号令查看自带的插件:

ls ~/.oh-my-zsh/plugins/

对于自带插件的功效及应用,你可以前往 Oh My Zsh 官方 Wiki 查看。

要启用某个插件,只必要用 vim ~/.zshrc 编纂 zsh 配置文件,定位到 plugins 一行,在括号中增加必要的插件称号,以空格分开。留存退出后,别忘了执行  source ~/.zshrc 使配置登时见效。

点窜 plugins 一行的配置启用插件

204822d238a0403aba70bfbd9ed24a27.png

我应用的插件git

默认启用的插件,提供了种种 git 号令的缩写。其 官方申明 提供了所有缩写的参考。

z

自带插件,增加到配置文件中即可启用,可以赞助你疾速跳转到走访过的文件夹。具体应用要领请自行 Google 或参考 GitHub 文档。

zsh-syntax-highlighting

输入精确的常用号令会以绿色高亮显示,输入错误则会显示其余的色彩。应用以下号令安置:

git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

After downloading realized, do not forget to plugins zsh-syntax-highlighting added to the configuration file, and performs source ~ / .zshrc effective for the configuration.

zsh-autosuggestions

When entering orders, we will give orders to the proposed light-colored font, press → to completion. Apply the following orders placed:

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

After downloading realized, do not forget to plugins zsh-autosuggestions added to the configuration file, and performs source ~ / .zshrc effective for the configuration.

In order to remind the font color accurate display, we also need to perform:

echo "export TERM = xterm-256color" >> ~ / .zshrc # terminal affirmed Example

echo "ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE = 'fg = 10'" >> ~ / .zshrc # recommended configuration command text color

You can modify the number after fg = command to specify the recommended text color, and color digital correspondence table please refer here.

summary

At this point, you have achieved Oh My Zsh basic configuration in the macOS. Today you get a more beautiful end, I believe this allows you to manipulate the current situation more with less in the terminal. If you have any further questions can go to Macdown.com, all software is tested, but also a variety of material factors such as templates for you to choose.


Guess you like

Origin blog.51cto.com/14505326/2431349
Recommended