zsh 安装和配置
zsh安装
sudo apt install zsh git curl -y
如果git和curl没有安装顺带一起安装了
修改默认终端
chsh -s /bin/zsh
不能使用
sudo
安装Oh My Zsh
资源:
- ohmyzsh官网:ohmyz.sh/
- ohmyzsh github仓库:github.com/ohmyzsh/ohm…
- ohmyzsh安装指导页面:ohmyz.sh/#install
- 主题powerlevel9k github仓库(已停止更新):github.com/Powerlevel9…
- 主题powerlevel10k github仓库:github.com/romkatv/pow…
- Powerline安装docs:powerline.readthedocs.io/en/latest/i…
- nerd-fonts github仓库:github.com/ryanoasis/n…
- nerdfonts官网:www.nerdfonts.com/
- Maple Mono字体官网:font.subf.dev/zh-cn/
- Maple Mono github仓库:github.com/subframe753…
- zsh-autosuggestions插件仓库:github.com/zsh-users/z…
- awesome-zsh-plugins插件仓库:github.com/unixorn/awe…
- ohmyzsh插件仓库:github.com/ohmyzsh/ohm…
- zsh插件仓库(非官方):github.com/unixorn/awe…
ohmyzsh安装
-
Once you have zsh, you can install Oh My Zsh by simply running one of these commands:
Method Command curl sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"wget sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"fetch sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"**NOTE: the installer will rename an existing **
.zshrc ** file to ** .zshrc.pre-oh-my-zsh . -
Alternatively, the installer is also mirrored outside GitHub. Using this URL may be required if you're in a country like India or China, that blocks
raw.githubusercontent.com:Method Command curl sh -c "$(curl -fsSL https://install.ohmyz.sh)"wget sh -c "$(wget -O- https://install.ohmyz.sh)"fetch sh -c "$(fetch -o - https://install.ohmyz.sh)"
bash配置迁移至zsh
# 查看bash配置文件
cat ~/.bashrc
# 编辑zsh配置文件
vim ~/.zshrc
# 使新的zshrc生效
source ~/.zshrc
安装nerdfont字体
powerlevel10k默认支持 Source Code Pro, Font Awesome, Powerline和nerdfont,其中nerdfont可以发挥powerlevel10k全部样式。 所以直接安装nerdfont字体就行:
- 下载字体(otf或ttf格式) 可以到nerdfonts官网:www.nerdfonts.com/ 下载,这里推荐Maple Mono字体(官网:font.subf.dev/zh-cn/ ),支持等宽中文比较好
- 将字体复制或移动到
~/.local/share/fonts/中:
mv PowerlineSymbols.otf ~/.local/share/fonts/
- 刷新字体缓存
fc-cache -vf ~/.local/share/fonts/
- 设置终端字体样式 将终端的字体设置为nerdfont字体
powerlevel9k需要在
~/.zshrc中配置以下内容:POWERLEVEL9K_MODE='nerdfont-complete'
安装主题powerlevel10k
- 下载主题文件至ohmyzsh:
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
- 在
~/.zshrc中修改主题:
ZSH_THEME="powerlevel10k/powerlevel10k"
修改保存后运行. ~/.zshrc
- 重启启动终端,会提示配置powerlevel10k,按照步骤完成样式配置
更新powerlevel10k主题
git -C "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" pull
安装zsh插件
- 下载插件 这边推荐安装2个插件: 自动补全:github.com/zsh-users/z… 高亮:github.com/zsh-users/z…
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中的plugins,修改配置:
plugins=(
git
zsh-autosuggestions
zsh-syntax-highlighting
)
- 应用配置:
. ~/.zshrc
root用户配置
以上的配置仅针对当前用户的配置,使用sudo su -进入root后还是默认的bash,因此需要在root下再次配置:
- 设置默认终端
- 安装配置ohmyzsh
- 安装字体
- 安装主题
- 安装插件
ohmyzsh更新
upgrade_oh_my_zsh