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

Re: loading a set of functions



On Sep 13, 11:42am, Gaspar Bakos wrote:
}
} <installation path>/share/zsh/3.1.9/functions
} 
} - Is it possible to load eg. all of them?

Yes, you can do for example

    autoload $^fpath/*(-.:t)

where $^fpath means to concatenate what follows to every element of the
fpath array, and *(-.:t) means the tail (:t) of the path to every plain
file (.) or symlink that points to a plain file (-.).

A better scheme might be to use the zcompile command to compile the set
of functions you want (possibly all of them) and autoload the compiled
file.  You can do that with something like

    setopt extendedglob		# needed for *~*/README below
    autoload -U zrecompile
    zrecompile -p -U ~/all.zwc $^fpath/*~*/README(N-.)
    fpath=(~/all.zwc)		# need only this one file now
    autoload -w ~/all.zwc
    unsetopt extendedglob	# if you prefer normal globbing

where zrecompile is a wrapper function for zcompile which compiles the
all.zwc file only if some of the source files have changed.  Check out
`man zshcontrib' or look up zrecompile in zsh.info.  The *~*README is
to leave out the README file that gets installed in one of the fpath
directories by some versions of zsh.

Note that this may need tweaking if you use more than one version of zsh
with the same home directory (e.g., NFS mount on two different machines).
In that case you'll have to create a separate .zwc file for each version,
e.g., all-$ZSH_VERSION.zwc or some such.

Oh, and of course zcompile isn't availble in zsh 3.0.x or early versions
of 3.1.x, so if you have one of those you need to use my first example.

} - Or else, if I have my own functions in a separate directory, is it
} possible to autoload all without specifying their names separately?

If you add your separate directory to the fpath array, either of the
above will include it as well.  Or you can use similar commands just
for your own directory of files.

} - What is the difference between functions starting with "_" and the
} others?

It's a naming convention only.  The ones starting with underscore are
used by the completion system and generally can't be called directly
from the command line.

} - Are there any further libraries of functions not in the distribution?

There are a few functions that are in the distribution but are not
installed; these generally are examples drawn from older versions of
zsh where a newer/better way to accomplish the same thing now exists.

There are some user-contributed functions available on www.zsh.org if
you poke around, but nothing that would be described as a "library".

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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