zsh 安装和配置

78 阅读2分钟

zsh 安装和配置

zsh安装

sudo apt install zsh git curl -y

如果git和curl没有安装顺带一起安装了

修改默认终端

chsh -s /bin/zsh

不能使用sudo

安装Oh My Zsh

资源:

ohmyzsh安装

  • Once you have zsh, you can install Oh My Zsh by simply running one of these commands:

    MethodCommand
    curlsh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    wgetsh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
    fetchsh -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:

    MethodCommand
    curlsh -c "$(curl -fsSL https://install.ohmyz.sh)"
    wgetsh -c "$(wget -O- https://install.ohmyz.sh)"
    fetchsh -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字体就行:

  1. 下载字体(otf或ttf格式) 可以到nerdfonts官网:www.nerdfonts.com/ 下载,这里推荐Maple Mono字体(官网:font.subf.dev/zh-cn/ ),支持等宽中文比较好
  2. 将字体复制或移动到~/.local/share/fonts/中:
mv PowerlineSymbols.otf ~/.local/share/fonts/
  1. 刷新字体缓存
fc-cache -vf ~/.local/share/fonts/
  1. 设置终端字体样式 将终端的字体设置为nerdfont字体

powerlevel9k需要在~/.zshrc中配置以下内容:

POWERLEVEL9K_MODE='nerdfont-complete'
安装主题powerlevel10k
  1. 下载主题文件至ohmyzsh:
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ~/powerlevel10k
echo 'source ~/powerlevel10k/powerlevel10k.zsh-theme' >>~/.zshrc
  1. ~/.zshrc中修改主题:
ZSH_THEME="powerlevel10k/powerlevel10k"

修改保存后运行. ~/.zshrc

  1. 重启启动终端,会提示配置powerlevel10k,按照步骤完成样式配置
更新powerlevel10k主题
git -C "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k" pull
安装zsh插件
  1. 下载插件 这边推荐安装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
  1. 启用插件 找到~/.zshrc中的plugins,修改配置:
plugins=(
  git
  zsh-autosuggestions
  zsh-syntax-highlighting
)
  1. 应用配置:
. ~/.zshrc

root用户配置

以上的配置仅针对当前用户的配置,使用sudo su -进入root后还是默认的bash,因此需要在root下再次配置:

  1. 设置默认终端
  2. 安装配置ohmyzsh
  3. 安装字体
  4. 安装主题
  5. 安装插件

ohmyzsh更新

upgrade_oh_my_zsh