- Add file in specified directory and enable to use command.
- Shell function behaves like command.
- Command name and file name is pair.
mkdir -p "$HOME/.zsh/autoload"
Any path you like.
export FPATH="$HOME/.zsh/autoload/:$FPATH"
echo "echo hello zsh autoload" > "$HOME/.zsh/autoload/hello-zsh-autoload"
- File name will be command name.
- No need excutable permission.
- No need define function in file.
autoload -U hello-zsh-autoload
$ hello-zsh-autoload
hello zsh autoload
You can see a new command hello-zsh-autoload
was created as function by automatic.
$ which hello-zsh-autoload
hello-zsh-autoload () {
echo hello zsh autoload
}
export FPATH="$HOME/.zsh/autoload/:$FPATH"
autoload -U hello-zsh-autoload
Anytime you can use autoloaded command.
- zsh 5.5.1 (x86_64-apple-darwin17.5.0)