最近虚拟机安的有点多,每次都要重新配置一遍 Zsh,所以记录一下配置过程
安装 Zsh 和 Git
1 2
| sudo apt-get update sudo apt-get install zsh git
|
安装 Oh My Zsh
Oh My Zsh 是一个社区驱动的框架,用于管理 Zsh 配置。它包含了许多有用的功能,助手,插件和主题
1 2 3 4 5 6 7 8 9
| sh -c "$(wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
sh -c "$(curl -fsSL https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh)"
sh -c "$(wget -O- https://gitee.com/pocmon/ohmyzsh/raw/master/tools/install.sh)"
|
对于弹出的提示,输入y
即可
常用插件的安装
zsh-syntax-highlighting
语法高亮插件,可以在输入命令时,高亮显示命令的是否正确
1 2 3 4
| git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://gh.xmly.dev/https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
|
zsh-autosuggestions
自动补全插件,可以在输入命令时,自动补全命令
1 2 3 4
| git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
git clone https://gh.xmly.dev/https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
|
其他插件
可在下述仓库中找到更多有意思的插件:
https://github.com/unixorn/awesome-zsh-plugins
zshrc 配置
修改插件
编辑~/.zshrc
文件,找到plugins
行,修改为
1 2 3
| plugins=(git zsh-syntax-highlighting zsh-autosuggestions)
plugins=(git zsh-autosuggestions zsh-syntax-highlighting z extract web-search)
|
修改主题
编辑~/.zshrc
文件,找到ZSH_THEME
行,修改为
上面的是默认自带的主题,下面给出一个在 What’s the best theme for Oh My Zsh? 中排名靠前的主题 powerlevel10k
1 2 3 4
| git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
|
编辑~/.zshrc
文件,找到ZSH_THEME
行,修改为
1
| ZSH_THEME="powerlevel10k/powerlevel10k"
|
使配置生效
每次修改配置文件后,都需要执行以下命令使配置生效
相关文档链接
https://www.haoyep.com/posts/zsh-config-oh-my-zsh/