问题
I wrote my auto-completion function for make command, and placed it in ~/.zsh:
function __comp_make {
# ... function body ....
}
compctl -K __comp_make make
Unfortunately, it will not work because completion for make is already defined in
/usr/share/zsh/functions/Completion/Unix/_make
and apparently it takes precedence over my rule.
I had to rename _make to unused_make so it is not loaded at zsh initialization. It works, but it is rather ugly solution.
My question is: how should I set my completion rule so it takes precedence over the loaded defaults?
Related:
- How does one override an existing zsh keyboard completion?
Edit:
- zsh 4.3.17
回答1:
You need to set your fpath. See here.
In your ~/.zshrc, something like:
fpath=( ~/.zshfunctions $fpath )
where ~/.zshfunctions contains your custom completion files, should solve this for you. Note that your functions are loaded before the system ones. This will not work:
fpath=( $fpath ~/.zshfunctions )
As an aside, you're using compctl. It's old. I'd recommend using compsys instead, although a decent link explaining why escapes me at the moment.
These go into some detail about writing completion functions, including the fpath. You might find them useful for reference.
- Z-shell completion functions: introduction
- Writing z-shell completion functions
来源:https://stackoverflow.com/questions/17968024/zsh-disable-default-completion-for-make