agkozak/zsh-z

Autocompletion with `zap` package manager

Andrew15-5 opened this issue · 6 comments

I just wanted to say (it's not really an issue for me) that I had trouble getting autocompletion working with zap. But I figured it out and here is my MWE:

# .zshrc

[ -f $HOME/.local/share/zap/zap.zsh ] ||
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh)
source $HOME/.local/share/zap/zap.zsh

fpath=($ZAP_DIR/plugins/zsh-z $fpath) # the most critical line to get everything to work

autoload -Uz compinit
compinit

zstyle ':completion:*' menu select # optional

ZSHZ_CMD=f # I have an alias z=fg
plug agkozak/zsh-z

I don't know, maybe it's a bug with zap (it's v0.2) but all other plugins work as expected. This is the first one.

P.S. I was too lazy to hop on the train of "lazy cding" but now I can see the potential, specifically because autocompletion with paths is working. Really cool plugin, I can't wait when I'll feel all the gains it can give.

Zsh-z adds its own directory to fpath, so you shouldn't need to do that yourself. But compinit needs to run after fpath has been assembled. Try rearranging the lines so that compinit runs after plug agkozak/zsh-z and I think you'll find it all works.

Thank you, that works:

# .zshrc

[ -f $HOME/.local/share/zap/zap.zsh ] ||
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh)
source $HOME/.local/share/zap/zap.zsh

ZSHZ_CMD=f # I have an alias z=fg
plug agkozak/zsh-z

zstyle ':completion:*' menu select # optional

autoload -Uz compinit
compinit

Now I will remember that loading plugins comes first.

Update: If I put compinit at the end of my config file (after a bunch of settings and plugins) it considerably slows down init time for shell to be fully ready. Because of that and since I only have a problem with one plugin, I put the init lines right after this plugin — much faster.

Could you send me the exact .zshrc that you're using, with nothing omitted? I'll try to figure out what's happening.

Apparently this it has something to do with zap-zsh/completions. Because I shrank down my config and the noticeable loading time is still there.

Loads pretty fast:

[ -f $HOME/.local/share/zap/zap.zsh ] ||
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh)
source $HOME/.local/share/zap/zap.zsh

ZHOME=${ZDOTDIR:-$HOME}

HISTFILE=$ZHOME/.history.zsh
HISTSIZE=1000000000
SAVEHIST=1000000000

ZSHZ_CMD=f
plug agkozak/zsh-z

autoload -Uz compinit
compinit

plug zap-zsh/completions

Loads very slow:

[ -f $HOME/.local/share/zap/zap.zsh ] ||
zsh <(curl -s https://raw.githubusercontent.com/zap-zsh/zap/master/install.zsh)
source $HOME/.local/share/zap/zap.zsh

ZHOME=${ZDOTDIR:-$HOME}

HISTFILE=$ZHOME/.history.zsh
HISTSIZE=1000000000
SAVEHIST=1000000000

plug zap-zsh/completions

ZSHZ_CMD=f
plug agkozak/zsh-z

autoload -Uz compinit
compinit

So in this config, the plugin order matters (if you value your time).

P.S. I'm basically still a beginner to all the cool zsh stuff. But I'm nearly an expert at POSIX sh or Bash scripting, well at least I used them (still am) for several years in terminal and scripts every day. But zsh config file is nothing like bash, therefore I almost blindly copy and paste some lines and hope that they would work.

2 more points:

  • Now I'm confident that for some plugins order is important (I had one bug with hlissner/zsh-autopair and zsh-users/zsh-syntax-highlighting which must be plugged in this order)
  • I also noticed some weird slow-downs whenever I used terminal (kitty) and opened Neovim only today when I was not at home, which means I'm completely clueless what it was

This has nothing to do with this project (maybe 1%), but maybe it still has some value.