查看当前shell

echo $SHELL

zsh之oh-my-zsh主题配置_bash

zsh

安装zsh

yum install -y zsh

zsh之oh-my-zsh主题配置_bash_02

查看zsh

# 查看安装 zsh
which zsh

# 查看 zsh 版本
zsh --version

#查看支持的shell
cat /etc/shells

zsh之oh-my-zsh主题配置_bash_03

​zsh​​已添加到支持的​​shell​​中

切换​​shell​​​为​​zsh​

# 切换zsh shelll
chsh -s /bin/zsh

#重新查看目前默认的shell,已经变为bin/zsh
echo $SHELL

注意:


  • ​centos​​需要重启生效
  • ​.bash_profile​​​等​​Bash​​​中如有定制的设定时需要迁移至​​.zshrc​​文件中。

可以看到此时root用户的交互shell已经发生变化

cat /etc/passwd |grep '^root'
root:x:0:0:root:/root:/bin/zsh

oh-my-zsh


​oh-my-zsh​​​ 帮我们整理了一些常用的 ​​Zsh 扩展功能和主题​​​,避免重复造轮子,这里使用​​oh-my-zsh​


安装 oh-my-zsh

# githu 访问较慢
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh
# 或
wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O - | sh


# gitee (国内建议)
wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
sh install.sh

我这里使用​​gitee​​下载

[root@izgx8m1d9xjzhjz]~# wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
--2021-01-15 12:14:15-- https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh
Resolving gitee.com (gitee.com)... 180.97.125.228
Connecting to gitee.com (gitee.com)|180.97.125.228|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/plain]
Saving to: ‘install.sh’

[ <=> ] 9,825 --.-K/s in 0s

2021-01-15 12:14:15 (50.8 MB/s) - ‘install.sh’ saved [9825]

[root@izgx8m1d9xjzhjz]~# ls
install.sh

然后给install.sh添加权限:

#install.sh添加权限
chmod +x install.sh

# 执行
./install.sh

如果发现很慢,可以修改为gitee源,编辑​​install.sh​

默认设置

ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}

将中间两行改为:

REPO=${REPO:-mirrors/oh-my-zsh}
REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}

zsh之oh-my-zsh主题配置_bash_04

重新执行即可。

安装成功

[root@izgx8m1d9xjzhjz]~# vim install.sh 
[root@izgx8m1d9xjzhjz]~# chmod +x install.sh
[root@izgx8m1d9xjzhjz]~# ./install.sh
Cloning Oh My Zsh...
Cloning into '/root/.oh-my-zsh'...
remote: Enumerating objects: 1188, done.
remote: Counting objects: 100% (1188/1188), done.
remote: Compressing objects: 100% (1166/1166), done.
remote: Total 1188 (delta 23), reused 399 (delta 6), pack-reused 0
Receiving objects: 100% (1188/1188), 824.45 KiB | 0 bytes/s, done.
Resolving deltas: 100% (23/23), done.

Looking for an existing zsh config...
Using the Oh My Zsh template file and adding it to ~/.zshrc.

__ __
____ / /_ ____ ___ __ __ ____ _____/ /_
/ __ \/ __ \ / __ `__ \/ / / / /_ / / ___/ __ \
/ /_/ / / / / / / / / / / /_/ / / /_(__ ) / / /
\____/_/ /_/ /_/ /_/ /_/\__, / /___/____/_/ /_/
/____/ ....is now installed!


Before you scream Oh My Zsh! please look over the ~/.zshrc file to select plugins, themes, and options.

? Follow us on Twitter: https://twitter.com/ohmyzsh
? Join our Discord server: https://discord.gg/ohmyzsh
? Get stickers, shirts, coffee mugs and other swag: https://shop.planetargon.com/collections/oh-my-zsh

? ~

配置 zsh 主题ys

​vim ~/.zshrc​

修改主题:

ZSH_THEME="robbyrussell"
#改为
ZSH_THEME="ys"

修改插件:

plugins=(git)
#改为
plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

如果​​.bash_profile​​中有配置内容的话,还需要增加一行:

source ~/.bash_profile

更新配置文件

​source .zshrc​

发现同上报错是正常的,因为我们还没有下载插件,直接就配置了。

安装插件

安装zsh-syntax-highlighting

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

安装zsh-autosuggestions

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

安装完成后,重新更新配置:

​source .zshrc​

在编辑指令的时候,对于之前使用过的指令,按​​Tab​​键即可快速补全,非常好用。

配置zsh主题 powerlevel9k (推荐)

安装

$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

编辑 ​​~/.zshrc​​​来启用主题,在其中将​​ZSH_THEME​​ 改为

ZSH_THEME="powerlevel9k/powerlevel9k"

如果你还没有安装字体,那么可以使用下面的命令来安装所需字体。

安装 powerline字体

# 下载
git clone https://github.com/powerline/fonts.git

# 进入文件夹并安装
cd fonts
./install.sh

安装 Awesome-Terminal Fonts字体

git clone https://github.com/gabrielelana/awesome-terminal-fonts.git
cd awesome-terminal-fonts
./install.sh

安装nerd-fonts

#下载
git clone https://github.com/ryanoasis/nerd-fonts.git
#安装同上

zsh之oh-my-zsh主题配置_github_05

修改配置文件​​.zshrc​

#Path to your oh-my-zsh installation.
export TERM="xterm-256color"
export ZSH="/root/.oh-my-zsh"

#default
#ZSH_THEME="robbyrussell"
#ZSH_THEME="ys"
ZSH_THEME="powerlevel9k/powerlevel9k"

plugins=(git zsh-autosuggestions)
#plugins=(git zsh-syntax-highlighting zsh-autosuggestions)

source $ZSH/oh-my-zsh.sh