zsh
has a completion function for commands in PATH
named _path_commands
. You can configure the completion to use it for myFunc
by running:
compdef _path_commands myFunc
Note: this requires that the zsh completion system to be initialized. Usually (as set up by compinstall
) this happens in your ~/.zshrc
with
# some zstyle configurations autoload -Uz compinit compinit
Any calls to compdef
need to be done after compinit
. If you get "command not found" errors when running compdef
, I suggest setting up the completion system with compinstall
.
Note: for security, zsh will throw errors if any directories in your $fpath are world-writeable. If you receive the error:
zsh compinit: insecure directories, run compaudit for list. Ignore insecure directories and continue [y] or abort compinit [n]?
Do not simply hit y, but hit n and then try compaudit | xargs chmod g-w
as suggested at https://stackoverflow.com/questions/13762280/zsh-compinit-insecure-directories