I want to replace an existing zsh completion function and keep a reference to the original (from here). E.g. to make tab completion always suggest nice
as first word in a command line:
eval "$(declare -f _normal | sed '1s/.*/_original&/')"
_normal() {
if [[ $CURRENT == 1 ]] ; then
# suggest only "nice" as first word
_wanted commands expl "be nice" compadd nice
else
# do normal completion afterwards
_original_normal
fi
}
The problem, as far as I understand it right now, is that in a fresh zsh _normal
is not loaded yet:
PROMPT> functions _normal
_normal () {
# undefined
builtin autoload -XUz
}
yet, after I hit ⇥ for the first time, it is loaded:
PROMPT> functions _normal
_normal () {
local _comp_command1 _comp_command2 _comp_command skip
if [[ "$1" = -s ]]
then
skip=(-s)
else
skip=()
_compskip=''
<snap>
This means the above redefinition of _normal
cannot be done in my .zshrc, as only the builtin autoload
bit gets written to _original_normal
which then cannot get loaded (no file _original_normal
in the fpath
).
Is there a way how I can force loading _normal
?
PS: It appears doing the redefinition of _normal
works if I do it in a shell after hitting tab before.