zsh custom completion file not sourced properly
0
votes
1
answer
331
views
I encountered a strange behaviour regarding ZSH completion for my custom script and need some ideas, what went wrong and how to solve it.
I have written a little custom script
myscript
and also created a corresponding completion script _myscript
. The latter begins with the following lines as usual: #compdef myscript
(also tried #compdef _myscript myscript
with same result). At the beginning I had both files inside my ~/.local/bin
directory, which is part of my $PATH
. I also added it to my $fpath
so ZSH could find the completion script.
So far, so good. Everything worked fine with the completion of the myscript
command. But then I moved both files to my **.dotfiles** to share them through the corresponding git repo. My dotfiles contain a folder for completion script which is also part of my $fpath
. But when moved to this subdirectory of my dotfiles, completions stopped working...
I removed .zcompdump
to renew the completion assignments and tested different syntax to add the directory to my $fpath
, but nothing helped. I also called compinit
manually after removing .zcompdump
to be sure it is called after all assingments were executed.
The first strange thing is, that other completion scripts inside the dotfile directory are recongnised by ZSH completion system as it also contains the completion scripts for my rustup
and cargo
command. When grepping .zcompdump
after the different steps I tried, it always shows the assignments for both those commands but not for myscript
.
The second strange behaviour is, that when I move the completion script back to the ~/.local/bin
dir and restart ZSH, it suddenly recocgnises the script and completions start working again. And now I can also grep it inside my .zcompdump
Now I'm running out of ideas what could be the reason, especially since rustup
and cargo
completion is working properly from the same directory. It would be much more comfortable to have all my custom completion working from my dotfiles, so I can use them on different machines without much manual configuration. Of course, I know I could hardcode the completion assignment inside my zshrc
, but thats also not as portable as the regular fpath
It may be a minor aspect I'm missing, but hopefully someone knows the solution.
I can't offer much code, since it seems not to be due to my scripts code. JFYI: I'm running Manjaro Linux (with predefined ZSH setting, which I already checked).
Asked by lukeflo
(131 rep)
Feb 28, 2024, 09:23 PM
Last activity: Feb 29, 2024, 09:12 AM
Last activity: Feb 29, 2024, 09:12 AM