Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Re-loading files loaded via "autoload"
- X-seq: zsh-users 26929
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Philippe Troin <phil@xxxxxxxx>
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: Re-loading files loaded via "autoload"
- Date: Fri, 13 Aug 2021 04:29:15 +0200
- Archived-at: <https://zsh.org/users/26929>
- In-reply-to: <aeaa13fda1ea2aa79443f1ed966a6b25f4d5ef50.camel@fifi.org>
- List-id: <zsh-users.zsh.org>
- References: <CAMP9c5kjuw4sxS0ZsCTN_Vkd=4SZNhx8Vg3UCcoNPi-Y9TK3Rg@mail.gmail.com> <CAHYJk3SUHp9f_mb1WAa0yB6bXFhm4H0_MvV-2yYo=6or0kMgEg@mail.gmail.com> <aeaa13fda1ea2aa79443f1ed966a6b25f4d5ef50.camel@fifi.org>
On 8/12/21, Philippe Troin <phil@xxxxxxxx> wrote:
> On Wed, 2021-08-11 at 20:25 +0200, Mikael Magnusson wrote:
>> eg, we have this, which mentions it in a comment of the example code:
>> It is also possible to create a function that is not marked
>> as autoloaded,
>> but which loads its own definition by searching fpath, by using
>> `autoload -X'
>> within a shell function. For example, the following are
>> equivalent:
>>
>> myfunc() {
>> autoload -X
>> }
>> myfunc args...
>>
>> and
>>
>> unfunction myfunc # if myfunc was defined
>> autoload myfunc
>> myfunc args...
>
> I use this function as a convenience when I work on autoloaded
> functions:
>
> autoreload () {
> emulate -L zsh
> local i
> for i in $@
> do
> (( $+functions[$i] )) && unfunction $i
> autoload -U $i
> done
> }
Both unfunction and autoload -U will happily handle $@, so there's no
real need for the loop. You can redirect the unfunction 2> /dev/null
if you don't want to be informed that you specified a nonexisting
function as in the above.
You should also use - in case you ever want to specify a function
starting with - or +, eg unfunction - $@; autoload -U - $@ (another
non-equivalence in the code example above btw, -myfunc() autoload -X
will work as specified, but the second one will break for
-myfunc/+myfunc :)
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author