Zinit 加速你的 zsh —— 最强 zsh 插件管理器 Zinit

 


chsh -s $(which zsh)
然后 Log Out 重新登陆

 

https://zdharma-continuum.github.io/zinit/wiki/INTRODUCTION/

 

https://www.cnblogs.com/hongdada/p/14048612.html

 

https://www.dazhuanlan.com/ppma/topics/1664045

 

# 加载 powerlevel10k 主题
zinit ice depth=1;
zinit light romkatv/powerlevel10k

# zsh的history插件, 关闭share_history功能
zinit snippet OMZ::lib/history.zsh
unsetopt share_history

# zsh的completion插件, case-sensitive completion
zinit snippet OMZ::lib/completion.zsh
# CASE_SENSITIVE="true"

zinit snippet OMZ::lib/git.zsh
zinit snippet OMZ::plugins/git/git.plugin.zsh

zinit snippet OMZ::lib/clipboard.zsh

# Set terminal window and tab/icon title
zinit snippet OMZ::lib/termsupport.zsh
# DISABLE_AUTO_TITLE="true"

zinit snippet OMZ::lib/key-bindings.zsh
zinit snippet OMZ::lib/theme-and-appearance.zsh


zinit load agkozak/zsh-z
zinit light zsh-users/zsh-completions

 zinit ice lucid wait='0' atload='_zsh_autosuggest_start'
 zinit light zsh-users/zsh-autosuggestions

zinit ice lucid wait='0'
zinit light zsh-users/zsh-syntax-highlighting
zinit load zdharma
-continuum/history-search-multi-word

 


https://github.com/ohmyzsh/ohmyzsh/blob/master/templates/zshrc.zsh-template

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

 

安装fzf
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

安装autojump,需要手动安装dnf install autojump
zinit snippet OMZ::plugins/autojump


# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
  source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi

#
# .zshrc is sourced in interactive shells.
# It should contain commands to set up aliases,
# functions, options, key bindings, etc.
#

autoload -U compinit
compinit

#allow tab completion in the middle of a word
setopt COMPLETE_IN_WORD

## keep background processes at full speed
#setopt NOBGNICE
## restart running processes on exit
#setopt HUP

## history
#setopt APPEND_HISTORY
## for sharing history between zsh processes
#setopt INC_APPEND_HISTORY
#setopt SHARE_HISTORY

## never ever beep ever
#setopt NO_BEEP

## automatically decide when to page a list of completions
#LISTMAX=0

## disable mail checking
#MAILCHECK=0

# autoload -U colors
#colors

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

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
    zdharma-continuum/zinit-annex-as-monitor \
    zdharma-continuum/zinit-annex-bin-gem-node \
    zdharma-continuum/zinit-annex-patch-dl \
    zdharma-continuum/zinit-annex-rust

### End of Zinit's installer chunk


# Load powerlevel10k theme
zinit ice depth"1" # git clone depth
zinit light romkatv/powerlevel10k

# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh


zinit snippet OMZ::lib/history.zsh
unsetopt share_history

zinit snippet OMZ::lib/completion.zsh
# CASE_SENSITIVE="true"

zinit snippet OMZ::lib/git.zsh
zinit snippet OMZ::plugins/git/git.plugin.zsh

zinit snippet OMZ::lib/grep.zsh
zinit snippet OMZ::lib/clipboard.zsh
zinit snippet OMZ::lib/termsupport.zsh
zinit snippet OMZ::lib/key-bindings.zsh
zinit snippet OMZ::lib/theme-and-appearance.zsh

zinit snippet OMZ::plugins/autojump


zinit load agkozak/zsh-z
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-syntax-highlighting

zinit load zdharma-continuum/history-search-multi-word

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

 

 

https://www.huwenqiang.cn/articles/2021/10/02/1618970594540.html

ZSH启动慢

如果觉得ZSH启动过慢,可以执行如下命令zinit提供的插件进行检测

zinit module build

并根据提示将以下内容加到 ~/.zshrc最前面

module_path+=( "$HOME/.zinit/bin/zmodules/Src" )
zmodload zdharma/zinit

关闭并重新打开一个新的shell,执行 zpmod source-study -l即可查看到每个脚本的启动时间,将耗时较长的脚本延迟加载或删除以加快启动速度

如果提示找不到文件,可能需要修改编译参数,将 ~/.zinit/bin/zinit-autoload.zsh文件中下面这行添加 -Wno-implicit-function-declaration参数到 CFLAGS中重新执行编译命令即可

CPPFLAGS=-I/usr/local/include CFLAGS="-g -Wall -O3" LDFLAGS=-L/usr/local/lib ./configure --disable-gdbm --without-tcsetpgrp

 

 

https://zenlian.github.io/posts/tools/zsh-zinit/

延迟加载


zinit 称之为 Turbo模式,通过 wait 修饰符实现。可以让插件的加载延迟到整个 .zshrc 文件已经读取完毕,并且命令提示符已经显示之后。延迟加载那些启动慢的插件,可以大大提升 zsh 的启动速度(虽然 zinit 已经很快了!)。


1
2
zinit ice wait lucid atload'_zsh_autosuggest_start'
zinit light zsh-users/zsh-autosuggestions

上面这条命令让 autosuggestions 命令延迟加载。 wait 没有参数表示 zshrc 读取完毕后立刻(1ms)加载; lucid 是静默模式,插件加载完成后不显示提示; atload 指定了插件加载之后执行的命令。autosuggetstions 插件使用了 precmd hook, precmd hook 在每条命令提示符显示前都会执行,由于使用了延迟加载,第一条提示符显示前插件还没有被加载,所以第一条提示符显示时 autosuggestions 不可用。这里使用 atload 手动执行一次 precmd hook,正好修复了这个问题。


我个人没有使用这个功能,因为 zinit 已经很快了。主题插件可能启动会慢一些,但如果让主题插件延迟加载,会先显示一个简单的命令提示符,然后等主题插件加载完毕了再变为主题插件提供的命令提示符,这样的跳变看起来怪怪的。

 

 



 
posted @ 2022-12-18 11:35  sinferwu  阅读(1903)  评论(0编辑  收藏  举报