zinit icon indicating copy to clipboard operation
zinit copied to clipboard

[bug]: source .zshrc runs slower after repeating

Open QuasarRyan opened this issue 9 months ago • 1 comments

What happened?

Running source .zshrc or source ~/.zshrc takes longer and longer after repeating it. Use exec zsh or just zsh to restart the env will fix but repeating source .zshrc or source ~/.zshrc will still takes longer and longer. Use time (source .zshrc) or time (source ~/.zshrc)

Steps to reproduce

Add the following lines to .zshrc file and run source .zshrc again and again for a few times.

ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"

# Download zinit, if it's not there yet
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
#
# Switch the download link to my self-host repository Mirror
# [ ! -d $ZINIT_HOME/.git ] && git clone https://git.xcreeper.xyz:4433/Qu
# asarRyan/zinit.git "$ZINIT_HOME"
# Source/Load zinit
source "${ZINIT_HOME}/zinit.zsh"

Relevant output


Screenshots and recordings

It's running slower and slower. Image

It not just happens on macOS. This is Proxmox LXC Debian 12.7 bookworm. Image

Use exec zsh or just zsh once or just time (source .zshrc) for one or two times will fix.

Image

Operating System & Version

OS: darwin24.0 | Vendor: apple | Machine: x86_64 | CPU: arm64 | Processor: arm | Hardware: arm64

Zsh version

zsh 5.9 (arm64-apple-darwin24.0)

Terminal emulator

xterm-ghostty and xterm-256color

If using WSL on Windows, which version of WSL

None

Additional context

I didn't show the whole .zshrc file because even if there's # conda initialize and lots of export, removing the zinit itself will get rid of this and that's why I create this issue here in this repository. It happens on Apple Terminal too, and using ssh to connect to Proxmox LXC Debian 12 with the same .zshrc configuration won't help.

Code of Conduct

  • [x] I agree to follow this project's Code of Conduct

QuasarRyan avatar Mar 21 '25 08:03 QuasarRyan

The environment on Linux is as written below:

  • Debian 12 bookworm
  • zsh, fzf, lsd, git installed with package manager
  • ohmyposh, zoxide with manual install in $HOME/.local
  • enable en_US UTF.8 UTF.8 and zh_CN UTF.8 UTF.8 in /etc/locale.gen with this in .zshrc file but you can just remove these plugins, auto complete, fzf, zoxide and ohmyposh configuration.
# Set language environment
export LANG=zh_CN.UTF-8

# Set base PATH
export PATH=$HOME/bin:/usr/local/bin:$PATH:/usr/local/vim/bin
export MANPATH=/usr/local/man:$MANPATH
export PATH=$HOME/.local/bin:$PATH

# Set editor
export EDITOR=vim

# Set the directory to store zinit and plugins
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"

# Download zinit, if it's not there yet
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
#
# Switch the download link to my self-host repository Mirror
# [ ! -d $ZINIT_HOME/.git ] && git clone https://git.xcreeper.xyz:4433/QuasarRyan/zinit.git "$ZINIT_HOME"
# Source/Load zinit
source "${ZINIT_HOME}/zinit.zsh"

# Add in zsh plugins
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions
zinit light Aloxaf/fzf-tab

# Add in snippets
zinit snippet OMZP::git
zinit snippet OMZP::sudo
zinit snippet OMZP::command-not-found

autoload -Uz compinit && compinit

zinit cdreplay -q

# Key bindings
bindkey -e

bindkey "^p" history-search-backward
bindkey "^n" history-search-forward


# History
export HISTSIZE=5000
export HISTFILE="$HOME/.zsh_history"
export SAVEHIST=$HISTSIZE
export HISTDUP=erase
setopt appendhistory
setopt sharehistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups

# Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no
zstyle ':fzf-tab:complete:cd:*' fzf-preview '/bin/ls --color $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview '/bin/ls --color $realpath'

# Aliases
alias ls="lsd"
alias la="ls -a"
alias ll="ls -al"


# fzf and themes
export FZF_DEFAULT_OPTS=" \
--color=bg+:#313244,bg:#1e1e2e,spinner:#f5e0dc,hl:#f38ba8 \
--color=fg:#cdd6f4,header:#f38ba8,info:#cba6f7,pointer:#f5e0dc \
--color=marker:#b4befe,fg+:#cdd6f4,prompt:#cba6f7,hl+:#f38ba8 \
--color=selected-bg:#45475a \
--color=border:#313244,label:#cdd6f4"
source <(fzf --zsh)


eval "$(zoxide init zsh)"

# Add oh-my-posh
# eval "$(oh-my-posh init zsh)"
if [ "$TERM_PROGRAM" != "Apple_Terminal" ]; then
  eval "$(oh-my-posh init zsh --config $HOME/.config/ohmyposh/catppuccin_mocha.toml)"
fi

Here's the catppuccin_mocha.toml in $HOME/.config/ohmyposh/catppuccin_mocha.toml

version = 3
final_space = true

[palette]
  blue = '#89B4FA'
  green = '#A6E3A1'
  sky = '#89DCEB'
  closer = 'p:os'
  lavender = '#B4BEFE'
  os = '#ACB0BE'
  pink = '#F5C2E7'

[upgrade]
  source = 'cdn'
  interval = '168h'
  auto = false
  notice = false

[[blocks]]
  type = 'prompt'
  alignment = 'left'
  newline = true

  [[blocks.segments]]
    template = ' {{.Icon}} '
    foreground = 'p:os'
    type = 'os'
    style = 'plain'

  [[blocks.segments]]
    template = '{{.Path}} '
    foreground = 'p:blue'
    type = 'path'
    style = 'plain'

    [blocks.segments.properties]
      folder_icon = '....'
      home_icon = '~'
      style = 'agnoster'

  [[blocks.segments]]
    template = '{{ .HEAD }}{{ if and (eq .Ahead 0) (eq .Behind 0) }} ≡{{end}}{{ if gt .Ahead 0 }} ⭡{{.Ahead}}{{end}}{{ if gt .Behind 0 }} ⭣{{.Behind}}{{end}} {{ if .Working.Changed }}+{{ .Working.Added }} ~{{ .Working.Modified }} -{{ .Working.Deleted }} {{ end }}'
    foreground = 'p:lavender'
    type = 'git'
    style = 'plain'

    [blocks.segments.properties]
      branch_icon = ' '
      cherry_pick_icon = ' '
      commit_icon = ' '
      fetch_status = true
      fetch_upstream_icon = true
      merge_icon = ' '
      no_commits_icon = ' '
      rebase_icon = ' '
      revert_icon = ' '
      tag_icon = ' '

[[blocks]]
  type = 'prompt'
  alignment = 'right'

  [[blocks.segments]]
    type = 'executiontime'
    style = 'plain'
    foreground = 'yellow'
    template = '{{ .FormattedMs }}'

    [blocks.segments.properties]
      threshold = 500
      style = 'austin'

  # show programming languages versions
  # [[blocks.segments]]
  #   template = ' {{ if .PackageManagerIcon }}{{ .PackageManagerIcon }} {{ end }}{{ .Full }}'
  #   foreground = 'p:green'
  #   type = 'node'
  #   style = 'plain'

  #   [blocks.segments.properties]
  #     display_mode = 'context'
  #     home_enabled = true
  #     fetch_version = true

  # [[blocks.segments]]
  #   template = '  {{ .Venv }}'
  #   foreground = 'p:sky'
  #   type = 'python'
  #   style = "plain"

  #   [blocks.segments.properties]
  #     display_mode = 'context'
  #     home_enabled = true
  #     display_default = true
  #     fetch_virtual_env = true

  [[blocks.segments]]
    template = ' {{ .UserName }}@{{ .HostName }}'
    foreground = 'p:blue'
    type = 'session'
    style = 'plain'

  [[blocks.segments]]
    template = ' {{ .CurrentDate | date .Format }} '
    foreground = 'p:lavender'
    type = 'time'
    style = 'plain'

# set the running time on the second line
# [[blocks]]
#   type = 'rprompt'
#   overflow = 'hidden'

#   [[blocks.segments]]
#     type = 'executiontime'
#     style = 'plain'
#     foreground = 'yellow'
#     template = '{{ .FormattedMs }}'

#     [blocks.segments.properties]
#       threshold = 500
#       style = 'austin'

[[blocks]]
  type = 'prompt'
  alignment = 'left'
  newline = true

  [[blocks.segments]]
    template = '❱'
    # foreground = 'p:closer'
    foreground_templates = [
      "{{if gt .Code 0}}red{{end}}",
      "{{if eq .Code 0}}p:closer{{end}}",
    ]
    type = 'text'
    style = 'plain'

# [transient_prompt]
#   foreground_templates = [
#     "{{if gt .Code 0}}red{{end}}",
#     "{{if eq .Code 0}}p:closer{{end}}",
#   ]
#   template = '❱'
#   newline = true

[secondary_prompt]
  foreground = 'p:lavender'
  template = '>'

QuasarRyan avatar Mar 21 '25 08:03 QuasarRyan