Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Is the function $f defined and is not an autoload stub?



export f=add-zle-hook-widget

I'd like to test whether the shell function $f is available (callable).

The naive solution, (( ${+functions[$f]} )), is not specific: it always
returns 1 after after 'autoload $f', even if the function is not
actually available (= calling it will fail with "zsh: $f: function
definition file not found").

The next candidate, «if autoload +X $f 2>/dev/null», is not idempotent:
it returns 'false' if «autoload +X $f» had already been run.

I suppose I could do this:
.
    if autoload +X -- $f 2>/dev/null;
       [[ "${${(@f)"$(which -- $f)"}[2]}" != $'\t'$histchars[3]' undefined' ]];
    then
    fi
.
but I'm hoping there's a saner way....

Thanks,

Daniel
(before you ask: I'd rather not use is-at-least because feature checks
are better than version checks)



Messages sorted by: Reverse Date, Date, Thread, Author