目录

在mac系统上配置zsh

zsh简介

在上一篇理解zsh以及他的配置文件中已经对zsh有了一个大概的了解。这篇文章中,我们将在mac系统中去配置我们的zsh,让它更加具有生产力。

安装ohmyzsh

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with thousands of helpful functions, helpers, plugins, themes, and a few things that make you shout…

Oh My Zsh是一个令人愉快的、开源的、社区驱动的框架,用于管理您的Zsh配置。

使用curl安装 sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

安装成功后,效果就如下图所示

https://qiniu.ckfear.cn/blog/7771601.png

下面就去定制我们的zsh吧。

设置zsh主题

我们通过vim打开zsh的配置文件~/.zshrc,发现里面已经配置了默认主题。 ZSH_THEME="robbyrussell",如果你觉得这套主题无法满足你的需求,你可以更换其他主题。

我使用了pure主题,安装起来也很容易。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
$ brew install pure
$ vim ~/.zshrc

# 添加以下内容
# .zshrc

ZSH_THEME="" # 屏蔽zsh主题

source $ZSH/oh-my-zsh.sh # 以下内容需要在这之后执行

fpath+=/opt/homebrew/share/zsh/site-functions
autoload -U promptinit; promptinit
prompt pure

$ source ~/.zshrc # 使我们修改配置文件生效

最终效果如下

https://qiniu.ckfear.cn/blog/4546718.png

pure主题已经设置完成了,如果你想做一些自定义的设置,去pure的主页设置符合自己的配置项,如果你不喜欢这个主题,你可以通过github搜索zsh theme关键字,会找到很多zsh主题,你可以选择自己感兴趣的。

下面,我们添加一些常用的zsh插件,让它更加易于使用。

安装zsh插件

zsh-autosuggestions

地址:https://github.com/zsh-users/zsh-autosuggestions

安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# zsh-autosuggestions
$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

$ vim ~/.zshrc

# ~/.zshrc
plugins=( 
    # other plugins...
    zsh-autosuggestions
)

$ source ~/.zshrc # 使我们修改配置文件生效

作用

在shell中输入命令时会匹配历史并给予提示,按→补全

https://qiniu.ckfear.cn/blog/6485847.png

zsh-syntax-highlighting

地址:https://github.com/zsh-users/zsh-syntax-highlighting

安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

$ vim ~/.zshrc

# ~/.zshrc
plugins=( 
    # other plugins...
    zsh-syntax-highlighting
)

$ source ~/.zshrc # 使我们修改配置文件生效

作用

增加了语法高亮,在交互式终端中,会突出显示命令。

https://qiniu.ckfear.cn/blog/5409156.png

z

z是ohMyZsh自带的插件,只需要在plugins中添加z即可

安装

1
2
3
4
5
6
7
8
9
$ vim ~/.zshrc

# ~/.zshrc
plugins=( 
    # other plugins...
    z
)

$ source ~/.zshrc # 使我们修改配置文件生效

作用

记录常用目录,进行快速跳转

vi-mode

vi-mode是ohMyZsh自带的插件,只需要在plugins中添加vi-mode即可

安装

1
2
3
4
5
6
7
8
9
$ vim ~/.zshrc

# ~/.zshrc
plugins=( 
    # other plugins...
    vi-mode
)

$ source ~/.zshrc # 使我们修改配置文件生效

作用

因为在交互式终端中移动光标非常麻烦,所以提供了vi模式进行编辑。

to be continued…