安装zsh

Ubuntu

1
sudo apt install -y zsh

Centos

1
sudo yum install -y zsh

设置默认的Shell为zsh

centos7 下需要单独安装chsh

1
sudo yum install util-linux-user

然后设置默认Shell

1
chsh -s /bin/zsh

安装git

注:已经安装完成的可以略过

Ubuntu

1
sudo apt install -y git

Centos

1
sudo yum install -y git

安装 oh-my-zsh

安装curl

1
sudo apt install -y curl

GitHub

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

Gitee

1
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)"

Oh My Zsh配置

主题,插件等相关配置都在~/.zshrc这个文件中,输入

1
nano .zshrc

修改ZSH_THEME=”robbyrussell”ZSH_THEME=”random”每次打开都是随机主题,也可以固定自己喜欢的主题

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/home/xiangyu/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="random"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

更新配置

1
source .zshrc

配置插件

还是 ~/.zshrc 文件,中间靠下有plugins这句话,这里可以看到我们目前启用的插件,在里面输入已安装的插件名,插件之间用空格间隔

1. zsh-syntax-highlighting

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

安装

GitHub

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

Gitee

1
git clone https://gitee.com/meatball-org-cn/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

在 ~/.zshrc 中配置

1
nano .zshrc
1
2
3
4
5
6
7
8
9
10
11
12
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git zsh-syntax-highlighting)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

更新配置

1
source .zshrc

2. zsh-autosuggestions

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

安装

GitHub

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

Gitee

1
git clone https://gitee.com/meatball-org-cn/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

在 ~/.zshrc 中配置

1
nano .zshrc
1
2
3
4
5
6
7
8
9
10
11
12
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

更新配置

1
source .zshrc