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

Re: order of sourcing



On Tue, Jan 17, 2023 at 10:10 PM Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
>
> In my .zshrc, to source all my functions I just switch to the directory
> where they're stored and:
>
>      for aa in *(.); do source $aa; done
>
> ... seems fine, but sometimes I'm editing one function or another and I
> run into 'not found' issues, like some subsidiary function has been
> 'lost'.  Sourcing it's file fixes the 'not found' but I'm wondering if
> there's some standard way of insuring that function files are sourced in
> a preferred order.  For some of them I've renamed the files in an
> alphabetical order since the above code seems to source the files
> alphabetically.  But it's add hoc and messy.  Dunno, I could list them
> all in a file in preferred order and then source that file.  But what's
> the done thing?

The standard solution is to autoload functions. It solves a bunch of
other problems that you get when sourcing files with function
definitions:

- You no longer pay the startup time penalty.
- You can rely on the standard options being in effect when the
function is parsed.
- You can rely on there being no aliases when the function is parsed.

Roman.




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