Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
autoloading fpath (was Re: Announce of Zsh Navigation Tools)
- X-seq: zsh-workers 36529
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: autoloading fpath (was Re: Announce of Zsh Navigation Tools)
- Date: Sun, 13 Sep 2015 09:11:18 -0700
- In-reply-to: <CAKc7PVDy6CebMQ=ST5UBz2Bo+-gh2tyZJSooOCJQx=dsRmkr6w@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAKc7PVCFRY-e+KvHzYK-VFFeRhRWL+HPWThYSJsTtZr6L3CT-Q@mail.gmail.com> <55F465E6.1040405@eastlink.ca> <CAKc7PVDy6CebMQ=ST5UBz2Bo+-gh2tyZJSooOCJQx=dsRmkr6w@mail.gmail.com>
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
zsh_default_functions=~/.zsh-default-functions.zwc
if ! zcompile -t $zsh_default_functions >&/dev/null
then
# 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)
fi
if [[ -f $zsh_default_functions ]]
then
fpath=( $zsh_default_functions )
autoload -w $zsh_default_functions
fi
Messages sorted by:
Reverse Date,
Date,
Thread,
Author