ZSH配置

ZSH配置

1. 安装

准备工作

安装zsh

1
2
3
4
# ubuntu下
apt install -y zsh
# centos下
yum install -y zsh

设置zsh为默认shell

1
chsh -s /bin/zsh

安装git, wget

1
2
3
4
# ubuntu下
apt install -y git wget
# centos下
yum install -y git wget

安装 oh-my-zsh

使用wget获取安装脚本

1
wget https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh

找到以下部分

1
2
3
4
5
# Default settings
ZSH=${ZSH:-~/.oh-my-zsh}
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}

把中间两行修改为:

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

:wq! 保存 sh install.sh 执行

2. 配置

基础配置

编辑 ~/.zshrc

1
2
3
4
5
6
# 解开第二行环境变量注释
export PATH=$HOME/bin:/usr/local/bin:$PATH
# 禁用自动更新
DISABLE_AUTO_UPDATE="true"
# 设置皮肤
ZSH_THEME="steeef"

安装插件

安装 zsh-autosuggestions 用于命令补全

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

将插件添加至配置文件~/.zshrc中, 将 plugins=(git) 替换为

1
2
3
4
plugins=(
git
zsh-autosuggestions
)

之后执行 source ~/.zshrc 即可生效

如果字体不清晰,可以修改 ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh 内的 ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=240'

注: 颜色值参考

配色参考

安装 zsh-syntax-highlighting 用于语法高亮

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

将插件添加至配置文件~/.zshrc

1
2
3
4
5
plugins=(    
git
zsh-syntax-highlighting
zsh-autosuggestions
)

git-bash 安装zsh

一文搞定 Windows Terminal 设置与 zsh 安装【非WSL】

Windows在git-bash安装zsh - 掘金


ZSH配置
https://leo03w.github.io/2022/09/23/ZSH 配置/
作者
Leo
发布于
2022年9月23日
许可协议