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

Re: PATH: autoload with explicit path

On Dec 11, 10:18pm, Peter Stephenson wrote:
} I wanted to autoload a function from an explicit path.
} [...] it strikes me it's a bit mean of the shell not simply to do
} something sensible with
} autoload +X /path/to/myfunc

For +X only, this can be accomplished by

    FPATH=/path/to autoload +X myfunc

Sebastian's plugin manager uses this.

} That doesn't do anything sensible at the moment --- relative paths to
} functions do, with the full relative path as the name, which is entirely
} consistent, but absolute paths don't and in fact it tries the name as a
} relative path anyway which seems Just Plain Wrong.

If I understand what you're saying, that means

    autoload this/here/file

creates a function named "this/here/file" by loading "file" from
$^fpath/this/here  ... yes?

And then (before this patch)

    autoload /this/here/file

creates a function named "/this/here/file" from the same location?

So after this patch there is no way to autoload a function whose name
begins with a slash.  Not that it was especially useful to be able to
do so, just confirming.

} autoload -Uz /path/to/myfunc
} defines myfunc to be found in the directory /path/to by reusing the
} filename element of the shfunc structure that's currently unused at this
} stage.
} This seemed quite a useful feature.

Yes, this is specifically what Sebastian and (I think) Ray were asking
for several months ago.

If I may make a suggestion -- an equally useful variation would be for
autoload to search the $fpath at the time of the autoload command and
store the path where the file is found *iff* it is found.  This would
be sort of like doing

    autoload -Uz $^fpath/myfunc(N)

except that it handles the situation where $fpath does not yet contain
the "myfunc" file.

Another useful variation might be to fall back to the current fpath if
the function isn't found at the specified location.

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