Zsh 安装及初始化配置
作者: Byron 最后更新: 2023-04-02
切换默认shell为zsh,自动补全和历史记录插件,ohmyzsh
Zsh is a shell designed for interactive use, although it is also a powerful scripting language.
目录
Zsh 安装
# 查看当前使用的shell
echo $SHELL
# /bin/bash 默认是bash
# 查看有哪些shells
cat /etc/shells
# 安装 zsh
sudo apt-get install zsh -y
# 查看zsh版本
zsh --version
# 安装后zsh 后cat /etc/shells 才有/bin/zsh /usr/bin/zsh
# 切换成zsh
chsh -s $(which zsh)
# 或者这条命令
chsh -s /usr/bin/zsh
ohmyzsh 安装
Oh My Zsh is an open source, community-driven framework for managing your zsh configuration.
# 安装 ohmyzsh
git clone https://github.com/ohmyzsh/ohmyzsh.git ~/.oh-my-zsh
# 使用预置配置文件
cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc
Zsh插件
# 高亮 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
# ~/.zshrc
# 启用插件
plugins=(
# 内置插件,直接填写启用即可(选择)
# git
git
# 根据过往目录切换记录快速跳转
z
# 按两下esc键,用sudo权限
sudo
# 记录历史输入的zsh命令,自动提示,快速使用
zsh-autosuggestions
# zsh 命令高亮
zsh-syntax-highlighting
)
# 每次修改了这个`.zshrc`配置文件,需要重载一下,才能生效。
source ~/.zshrc
# 也可以封装成一个简写命令 alias,这样每次输入rl就可以重载
alias rl='source ~/.zshrc'