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

autoloading fpath (was Re: Announce of Zsh Navigation Tools)

On Sep 13, 11:10am, Sebastian Gniazdowski wrote:
} I the rest of the emails you apparently have an idea of a
} autostart-functions directory that would automatically do "autoload
} {function}" for each file placed there. It would make installation of
} scripts like ZNT easier and I thought about such directory too.

This is effectively what "compinit" does for every file in the $fpath
that is named beginning with an underscore.  It reads the first line
of every such file to decide what to do with it.

While we're on the subject, though, take a look at the "zcompile"
builtin and the "zrecompile" utility.  If you zcompile a collection
of functions into a .zwc file, you can --

-- add the .zwc file name directly to $fpath and it will be searched
   like a directory at autoloaded-function execution time

-- specify the -z / -k behavior options at zcompile time so they don't
   have to be passed to autoload

-- easily autoload everything in the file:   autoload -w functions.zwc

ZWC files are machine-independent but zsh-version-dependent.  They get
memory-mapped when that's supported so the OS pages them efficiently.
The drawbacks are the version dependency if you frequently rebuild a
bleeding-edge shell (but see zrecompile) and that zcompile doesn't yet
support "sticky emulation" in any meaningful way.  Also, a ZWC file is
not like an archive file (e.g. a ZIP); you can't append or remove
individual functions, the whole file has to be rebuilt.

Finally, for Ray, you can for example replace your entire $fpath with
a single ZWC file:

    # Assume starting here with the default $fpath
    if ! zcompile -t $zsh_default_functions >&/dev/null
      # File is missing or out of date.  Rebuild it.
      # Removes the file if any function cannot be compiled.
      zcompile $zsh_default_functions $^fpath/*(N.:A)
    if [[ -f $zsh_default_functions ]]
      fpath=( $zsh_default_functions )
      autoload -w $zsh_default_functions

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