最近多次重复配置Linux环境,每次都要重新搜索教程重新配置终端,在此对终端配置过程进行一个汇总,使用Oh My Zsh对终端进行美化

下载与安装

安装Oh My Zsh首先要安装Zsh,本文操作都在Ubuntu下进行

1
sudo apt-get install zsh

然后安装Oh My Zsh,可以通过curl或wget的方式进行安装,每种方式提供Github和国内镜像两种下载渠道

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/mirrors/oh-my-zsh/raw/master/tools/install.sh)"

wget安装

Github
1
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"
Gitee
1
sh -c "$(wget -O- https://gitee.com/pocmon/mirrors/raw/master/tools/install.sh)"

至此,Oh My Zsh就安装完毕了,但是还没有达到自己想要的美化的程度

主题配置

Oh My Zsh默认会自带一些主题,个人通常喜欢用Powerlevel10k

Powerlevel10k安装

Github

1
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Gitee

1
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

Powerlevel10k配置

在Zsh的配置文件~/.zshrc中将主题改为

1
ZSH_THEME="powerlevel10k/powerlevel10k"

修改完成并保存后需要重新应用一下配置文件

1
source ~/.zshrc

应用后新主题会自动进行一些问题的询问来帮助配置主题样式

通过询问与选择后可以达到的终端样式如下

询问过程退出后如果想重新进入这个配置过程可以在终端中输入下面的命令:

1
p10k configure

使用Powerlevel10k主题时,会有很多图标在终端显示,需要终端字体支持才可以显示完整,我个人使用的是 CodeNewRoman Nerd Font,官方推荐的字体为Meslo Nerd Font。同时还有其他Nerd Font字体可供选择。

插件的安装

在Oh My Zsh中有很多插件可供使用,其中最常用的是zsh-autosuggestionszsh-syntax-highlighting

通常使用下面的命令进行插件的安装:

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

安装完成后在配置文件~/.zshrc中添加对应的插件

1
2
3
4
5
plugins=( 
# other plugins...
zsh-syntax-highlighting
zsh-autosuggestions
)

修改完成后重启Zsh或者使用source命令应用配置文件

卸载Oh My Zsh

终端输入命令

1
uninstall_oh_my_zsh