zsh & oh-my-zsh 安装

本文介绍了 zsh & oh-my-zsh 和一些插件的安装过程。

一、安装

1
2
3
4
5
6
# Ubuntu
apt-get install zsh
# CentOS
yum install zsh

sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

二、主题

1
2
3
4
5
6
vim ~/.zshrc

# 找到 ZSH_THEME
# 默认主题是 robbyrussell
# 可以参考 https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="agnoster"

三、插件

1. zsh-syntax-highlighting

高亮语法,输入正确语法会显示绿色,错误的会显示红色,使得我们无需运行该命令即可知道此命令语法是否正确。

1
2
3
4
5
6
7
8
9
10
# 安装
git clone https://gitee.com/chenming_c/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

# 配置
vim ~/.zshrc

plugins=(其他的插件 zsh-syntax-highlighting)

# 启用
source ~/.zshrc

2. zsh-autosuggestions

自动补全,只需输入部分命令即可根据之前输入过的命令提示,按右键 → 即可补全。

1
2
3
4
5
6
7
8
9
10
# 安装
git clone https://gitee.com/chenming_c/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

# 配置
vim ~/.zshrc

plugins=(其他的插件 zsh-autosuggestions)

# 启用
source ~/.zshrc

3. extract

一个 zsh 自带的插件,让你不需要再记关于解压的任何命令,直接执行 extract <filename> 即可。

1
2
3
4
5
6
7
# 配置
vim ~/.zshrc

plugins=(其他的插件 extract)

# 启用
source ~/.zshrc

4. z

一个 zsh 自带的插件,可以直接进行目录跳转 z <dirname> 即可。

1
2
3
4
5
6
7
# 配置
vim ~/.zshrc

plugins=(其他的插件 z)

# 启用
source ~/.zshrc

四、卸载

1
uninstall_oh_my_zsh

五、快速安装(可选)

1
2
3
4
5
6
7
8
9
git clone https://gitee.com/mirrors/oh-my-zsh.git ~/.oh-my-zsh
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
chsh -s $(which zsh)

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

ZSH_THEME="fino"
plugins=(git zsh-syntax-highlighting zsh-autosuggestions extract z)