z-shell / zi

✨ A Swiss Army Knife for Zsh - Unix Shell
https://wiki.zshell.dev
MIT License
745 stars 42 forks source link

[bug]: zsh startup never finishes and prompt is not shown unless aborted #183

Closed papanito closed 2 years ago

papanito commented 2 years ago

Environment

OSTYPE=linux-gnu CPUTYPE=x86_64 / MACHINE_TYPE=x86_64 ZSH_VERSION=5.9

Expected behavior

Zsh starts without problems

Current behavior

When starting zsh, never finishes and prompt is not shown unless aborted. I run zsh -i -x -c exit and then press Ctrl+C to abort it seems to stuck here

...
+add-zsh-hook:92> autoload -- @zi-scheduler
+/home/aedu/.zi/bin/zi.zsh:2743> ZI[HAVE_SCHEDULER]=1 
+/home/aedu/.zi/bin/zi.zsh:2745> functions -M -- zi_scheduler_add 1 1 -zi_scheduler_add_sh

zi_issue

Steps to reproduce

Simply run zsh with given config.

Code snippet

You can find my config and sources aliases etc. [here][https://github.com/papanito/dot-files/tree/0dde680e4e7da40e976795ee5d3b52d781abb843/personal/shell). This .zshrc is not working.

# 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

# Created by newuser for 5.2
# The following lines were added by compinstall
zstyle ':completion:*' auto-description 'specify: %d'
zstyle ':completion:*' completer _expand _complete _correct _approximate
zstyle ':completion:*' format 'Completing %d'
zstyle ':completion:*' group-name ''
zstyle ':completion:*' menu select=2
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*' list-colors ''
zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
zstyle ':completion:*' menu select=long
zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
zstyle ':completion:*' use-compctl false
zstyle ':completion:*' verbose true

zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'

autoload -Uz compinit
compinit
# End of lines added by compinstall

# Lines configured by zsh-newuser-install
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory autocd extendedglob notify hist_ignore_all_dups hist_ignore_space
bindkey -e
# End of lines configured by zsh-newuser-install

ZSH_DOTENV_FILE=.dotenv
if [ -f ~/.aliases ]; then . ~/.aliases ; fi
if [ -f ~/.functions ]; then . ~/.functions ; fi
if [ -f ~/.azure_completion ]; then . ~/.azure_completion ; fi

autoload -U add-zsh-hook                      # Load the zsh hook module. 
add-zsh-hook preexec pre_validation           # Adds the hook

# # enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
fi

# https://gnunn1.github.io/tilix-web/manual/vteconfig/
if [ $TILIX_ID ] || [ $VTE_VERSION ]; then
    source /etc/profile.d/vte.sh
fi

# https://z.digitalclouds.dev/docs/getting_started/installation/#-setup-zi-directory
if [[ ! -f $HOME/.zi/bin/zi.zsh ]]; then
  print -P "%F{33}▓▒░ %F{160}Installing (%F{33}z-shell/zi%F{160})…%f"
  command mkdir -p "$HOME/.zi" && command chmod g-rwX "$HOME/.zi"
  command git clone -q --depth=1 --branch "v1.0.1" https://github.com/z-shell/zi "$HOME/.zi/bin" && \
    print -P "%F{33}▓▒░ %F{34}Installation successful.%f%b" || \
    print -P "%F{160}▓▒░ The clone has failed.%f%b"
fi
zi_home="${HOME}/.zi"
source "${zi_home}/bin/zi.zsh"
autoload -Uz _zi
(( ${+_comps} )) && _comps[zi]=_zi

# https://github.com/z-shell/zsh-navigation-tools
zi load z-shell/zsh-navigation-tools

autoload znt-history-widget
zle -N znt-history-widget
bindkey "^R" znt-history-widget

zle -N znt-cd-widget
bindkey "^B" znt-cd-widget

zle -N znt-kill-widget
bindkey "^Y" znt-kill-widget

zi light zsh-users/zsh-autosuggestions
zi light z-shell/F-Sy-H

zi load romkatv/powerlevel10k
#zi ice depth=1; zi light romkatv/powerlevel10k

## https://z.digitalclouds.dev/docs/getting_started/overview/
zi snippet OMZ::plugins/archlinux
zi snippet OMZ::plugins/ansible
zi snippet OMZ::plugins/dotenv
zi snippet OMZ::plugins/docker
zi snippet OMZ::plugins/docker-compose
zi snippet OMZ::plugins/flutter
zi snippet OMZ::plugins/gnu-utils
zi snippet OMZ::plugins/gcloud
zi snippet OMZ::plugins/git
zi snippet OMZ::plugins/git-extras
zi snippet OMZ::plugins/github
zi snippet OMZ::plugins/gitignore
zi snippet OMZ::plugins/git-prompt
zi snippet OMZ::plugins/golang
zi snippet OMZ::plugins/gradle
zi snippet OMZ::plugins/helm
zi snippet OMZ::plugins/heroku
zi snippet OMZ::plugins/jump
zi snippet OMZ::plugins/kubectl
zi snippet OMZ::plugins/pip
zi snippet OMZ::plugins/python
zi snippet OMZ::plugins/ssh-agent
zi snippet OMZ::plugins/tmux
zi snippet OMZ::plugins/terraform

# https://github.com/zsh-users/zsh-history-substring-search
zi light zsh-users/zsh-history-substring-search
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down

export exa_params=('--git' '--classify' '--group-directories-first' '--time-style=long-iso' '--group' '--color-scale')
zi light zplugin/zsh-exa

eval "$(navi widget zsh)"
#eval "$(direnv hook zsh)"

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

Aditional information

Moving the sourcing of .aliases and .functions solved the issue for me

- ❮ ZI ❯ Analytics:
❯ compiled          – List plugins that are compiled
❯ zstatus           – Overall status
❯ module help       – Manage zpmod
❯ dtrace|dstart     – Start tracking what's going on in session
❯ dstop             – Stop tracking what's going on in session
❯ dreport           – Report what was going on in session
❯ dunload           – Revert changes recorded between dstart and dstop
❯ dclear            – Clear report of what was going on in session
❯ bindkeys          – List bindkeys
❯ clist|completions – List completions in use
❯ cdlist            – Show compdef replay list
❯ csearch           – Search for available completions from any plugin
❯ man               – Show manual
❯ ls                – List snippets in formatted and colorized manner
❯ status            [--all] [plugin]|URL – Git status for plugin or svn status for snippet
❯ report            [--all] [plugin] – Show reports
❯ times             [-s][-m][-a] – Statistics on plugin load times, sorted in order of loading
❯ glance            [plugin] – Look at plugin's source
❯ stress            [plugin] – Test plugin for compatibility with set of options
❯ changes           [plugin] – View plugin's git log
❯ recently          [time] – Show plugins that changed recently (e.g.: 1 month 2 days)
❯ cd                [plugin] – Enter plugin's directory; also support snippets, if feed with URL
❯ loaded|lists      [keyword] – Show what plugins are loaded (filter: keyword)

Self-service

Have you read the Contributing Guidelines?

Are you familiar with Contributor Covenant Code of Conduct?

Contact Details

papanito@wyssmann.com

ss-o commented 2 years ago

Unable to reproduce the issue as the given configuration passes tests and loads. Seems that functions.zsh, and aliases.zsh are missing.

It indicates that the issue with the functions.zsh file while adding the function hooks:

add-zsh-hook preexec pre_validation

and also related with:

https://github.com/z-shell/zi/blob/76cfe8ebaf893b916e81aa7c4ece4700da252907/zi.zsh#L2745


You can use docker run --rm -it -h zd@docker ghcr.io/z-shell/zd:zsh-5.9 to help reproduce the issue. (image: vim editor, alpine linux)

papanito commented 2 years ago

Well the function is defined in ~/.functions, which is sourced before the hook

if [ -f ~/.functions ]; then . ~/.functions ; fi
if [ -f ~/.azure_completion ]; then . ~/.azure_completion ; fi

autoload -U add-zsh-hook                      # Load the zsh hook module. 
add-zsh-hook preexec pre_validation           # Adds the hook
ss-o commented 2 years ago

Well the function is defined in ~/.functions, which is sourced before the hook

if [ -f ~/.functions ]; then . ~/.functions ; fi
if [ -f ~/.azure_completion ]; then . ~/.azure_completion ; fi

autoload -U add-zsh-hook                      # Load the zsh hook module. 
add-zsh-hook preexec pre_validation           # Adds the hook

Your configuration has quite a few issues, and bad practices. For this specific issue you have a function:

# finds all functions defined in any shell script secified, including .bashrc
function functions() { 
   read -p $1; sort -d $REPLY | grep "() {" | sed -e 's/() {//g' | less;
}

It is a shell built-in command and has to be removed/renamed to solve this issue (check: which functions).

I recommend updating/fixing all dotfiles. Here are some references to take into consideration:

https://github.com/z-shell/playground/tree/main/profiles https://z.digitalclouds.dev/community/zsh_handbook https://z.digitalclouds.dev/community/zsh_plugin_standard#preventing-function-pollution

It is possible to create dotfiles (zi create) as a zsh-plugin and simply load it with ZI (zi light papanito/<your-repo-name>).

Example dotfiles.plugin.zsh:

# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
#
#https://z.digitalclouds.dev/community/zsh_plugin_standard#zero-handling
0="${ZERO:-${${0:#$ZSH_ARGZERO}:-${(%):-%N}}}"
0="${${(M)0:#/*}:-$PWD/$0}"

# Autoload personal functions
fpath=("${0:h}/functions" "${fpath[@]}")
autoload -Uz $fpath[1]/*(.:t)

typeset -gA Local
Local[CONFIG_DIR]="${0:h}"
Local[THEMES_DIR]="${0:h}/themes"
Local[COMPLETIONS_DIR]="${0:h}/completions"
Local[COOL_STUFF_HERE_DIR]="${0:h}/some_cool_stuff"
papanito commented 2 years ago

thanks for having a look, will read through the links you provided and adjust my dotfiles.

the doc is amazing and really helps me better understand zsh.

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale. Please make sure to update to the latest version and check if that solves the issue. Let us know if that works for you by leaving a 👍 Because this issue is marked as stale, it will be closed and locked in 7 days if no further activity occurs. Thank you for your contributions!

github-actions[bot] commented 2 years ago

Issue closed and locked due to lack of activity. If you encounter this same issue, please open a new issue and refer to this closed one.