In my .zshrc file I have written a function based on git log:
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:
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, 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 :
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