使用zinit代替ohmyzsh

由于ohmyzsh的复杂和臃肿,导致其启动速度不尽人意,并且第三方插件的安装和管理需要手动进行,所以打算用zinit来代替ohmyzsh,以获得更好的性能以及使用体验

安装

使用官方提供的脚本

sh -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma/zinit/master/doc/install.sh)"

配置

配置文件同样是写在.zshrc
zinit提供了对ohmyzsh的兼容,以利用其庞大的生态,所以通过配置可以直接获得ohmyzsh相同的体验

### Added by Zinit's installer
if [[ ! -f $HOME/.zinit/bin/zinit.zsh ]]; then
    print -P "%F{33}▓▒░ %F{220}Installing %F{33}DHARMA%F{220} Initiative Plugin Manager (%F{33}zdharma/zinit%F{220})…%f"
    command mkdir -p "$HOME/.zinit" && command chmod g-rwX "$HOME/.zinit"
    command git clone https://github.com/zdharma/zinit "$HOME/.zinit/bin" && \
        print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
        print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi

source "$HOME/.zinit/bin/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
### End of Zinit's installer chunk
# 这部分直接使用了ohmyzsh的部分库,以获得相同的体验
zinit snippet OMZL::completion.zsh
zinit snippet OMZL::directories.zsh
zinit snippet OMZL::git.zsh
zinit snippet OMZL::history.zsh
zinit snippet OMZL::key-bindings.zsh
zinit snippet OMZL::termsupport.zsh
zinit snippet OMZL::theme-and-appearance.zsh

zinit snippet OMZP::git
zinit cdclear -q
# 主题配置
zinit snippet OMZT::ys

# 插件
zinit light zsh-users/zsh-autosuggestions # 命令提示
zinit light zdharma/fast-syntax-highlighting # 语法高亮
zinit light zsh-users/zsh-completions # 命令补全

# 一些别名
alias setwww="chmod 755 -R /root/myapps/www && chown 101:101 -R /root/myapps/www"

# 环境变量
export TERM='xterm-256color'
export EDITOR='vim'
export LC_ALL=en_US.UTF-8
export ARCHFLAGS="-arch x86_64"
export ANDROID_HOME=$HOME/android-sdk
export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/build-tools/27.0.3:$ANDROID_HOME/tools/bin
export RCLONE_CONFIG=$HOME/tools/rclone/rclone.conf

常用命令

zinit self-update # 更新zinit
zinit update # 更新插件