Skip to content

Instantly share code, notes, and snippets.

@vhbui02
Created April 29, 2023 03:23
Show Gist options
  • Save vhbui02/51bcc1fcde9434ac49c5a84d7f339d99 to your computer and use it in GitHub Desktop.
Save vhbui02/51bcc1fcde9434ac49c5a84d7f339d99 to your computer and use it in GitHub Desktop.
[Autoloading Functions in Fish] a.k.a lazy loading function #fish

Autoloading = Lazy loading

When fish needs to load a function

It searches through any dirs in the list variable $fish_function_path, for a file with name that consists the func name + suffix .fish and loads the 1st file it finds (remember, 1st)

If you put multiple funcs in 1 file .fish

The file (whole file, not just 1 func) will ONLY be loaded when you execute a function with the same name as that file.

Autoloading function don't support event handlers (a special kind of function)

These funcs are loaded on-demand, that means they're loaded only when needed. Since Fish don't know about the funcs that have the event (the event handlers) until they're loaded, Fish can't serve them.

=> Don't use funcsave command, these funcs should be stored in configuration file like ~/.config/fish/config.fish or ~/.config/fish/conf.d/ dir.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment