Zsh: completion not working for self-defined function based on git
1
vote
1
answer
102
views
In my
.zshrc
file I have written a function based on git log:
zsh
lg() {
git log \
--abbrev=12 \
--graph \
--oneline \
--color=always \
--format="%C(cyan)%h %C(blue)%ar %C(auto)%d %C(yellow)%s %C(white)%ae" "$@" |
fzf
To enable autocompletion for this function I have added to my .zshrc
:
zsh
compdef _git-log lg
The _git-log
function is indeed the basic completion function for git log in zsh.
It is inside /usr/share/zsh/functions/Completion/Unix/_git
.
But using this method as recommended [here](https://unix.stackexchange.com/questions/269791/zsh-tab-completion-for-function-with-git-commands) , doesn't work on my side.
After sourcing my .zshrc
and try to use my lg
command I keep getting in my terminal:
>$ lg (eval):1: command not found: _git-log
How to use completion functions from completions file for other function?
Edit:
As suggested by @Stéphane Chazelas , I used the load_helper_functions
from @Gille's answer .
At the end of my .zshrc
, I have now :
zsh
load_helper_functions () {
emulate -LR zsh
if ((!$+functions[$1])) || [[ $functions[$1] = 'builtin autoload'* ]]; then
autoload +X +U $1
functions[$1]=${functions[$1]%$'\n'*}
$1
fi
}
load_helper_functions _git
compdef _git lg=git-log
Asked by Clément
(35 rep)
Sep 4, 2024, 08:32 PM
Last activity: Sep 28, 2024, 01:34 PM
Last activity: Sep 28, 2024, 01:34 PM