Skip to main content

Zsh

Name Path Module
Zsh latest /fs00/software/zsh/latest zsh/latest
Zsh 5.8 /fs00/software/zsh/5.8 zsh/5.8

或从镜像站下载编译安装

Environment Modules

添加 Environment Modules 至 Zsh

echo "source /fs00/software/modules/latest/init/profile.sh" >> ~/.zshrc

命令行提示符

  • 因登录时需判断命令行提示符是否为$ ,因此建议保持 Bash 为默认 Shell,登录后通过下列命令切换至 Zsh
module load zsh/latest && exec zsh
  • 如设置 Zsh 为默认 Shell 或登录会自动切换至 Zsh,则必须更改 Zsh 的命令行提示符(环境变量PS1)以$ 结尾($+空格),否则登录会失败!

Oh My Zsh

安装

在本地克隆后获取安装脚本再进行安装

git clone https://mirror.nju.edu.cn/git/ohmyzsh.git
cd ohmyzsh/tools
REMOTE=https://mirror.nju.edu.cn/git/ohmyzsh.git sh install.sh

切换已有 Oh My Zsh 至镜像源

git -C $ZSH remote set-url origin https://mirror.nju.edu.cn/git/ohmyzsh.git
git -C $ZSH pull

升级

omz update

主题

Powerlevel10k

安装
git clone --depth=1 https://mirror.nju.edu.cn/git/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

编辑 ~/.zshrc 的主题 ZSH_THEME="powerlevel10k/powerlevel10k"

升级
cd ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k && git pull
256色终端

开启 xterm 终端的256色以便正确显示提示颜色

echo "export TERM=xterm-256color" >> ~/.zshrc
永久在左侧显示主机名

在集群中经常需要登录到各个节点,因此最好在左侧永久显示主机名防止误操作 编辑 ~/.p10k.zsh

  1. POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS中的context剪切到POWERLEVEL9K_LEFT_PROMPT_ELEMENTS的第一项
  2. 注释typeset -g POWERLEVEL9K_CONTEXT_{DEFAULT,SUDO}_{CONTENT,VISUAL_IDENTIFIER}_EXPANSION=这一行
  3. 更改typeset -g POWERLEVEL9K_CONTEXT_PREFIX=''

插件

zsh-autosuggestions

安装
git clone https://mirror.nju.edu.cn/git/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

编辑 ~/.zshrcplugins= 中添加 zsh-syntax-highlighting

plugins=( ... zsh-autosuggestions)
升级
cd ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions && git pull

zsh-syntax-highlighting

安装
git clone https://mirror.nju.edu.cn/git/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

编辑 ~/.zshrcplugins= 最后添加 zsh-syntax-highlighting

plugins=( [plugins...] zsh-syntax-highlighting)
升级
cd ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting && git pull