agkozak / zsh-z

Jump quickly to directories that you have visited "frecently." A native Zsh port of z.sh with added features.
MIT License
1.97k stars 77 forks source link

Autocompletion with `zap` package manager #78

Open Andrew15-5 opened 1 year ago

Andrew15-5 commented 1 year ago

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.

agkozak commented 1 year ago

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.

Andrew15-5 commented 1 year ago

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.

Andrew15-5 commented 1 year ago

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.

agkozak commented 1 year ago

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

Andrew15-5 commented 1 year ago

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.

Andrew15-5 commented 1 year ago

2 more points:

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