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

Re: A serious bug in execution – where to debug?

On Wed, 31 Jul 2019 at 14:40, Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
> ...
> How is this possible?
>   foo.zsh:  alias grep='grep --color=auto'
>   bar.zsh:  function bar() { grep hello <<<hello }
>   baz.zsh  alias grep='grep --color=auto'

Thanks for bringing this up into the light. It's a good example of the
problems with unloading. It also hints an extension to zplugin – to
test whether the alias' value is the one expected to be and hold the
unsetting/restoration of the alias if it isn't. So, if baz would set
alias grep='grep -B1 --color=auto', then things would work as
expected. And that's how it is with the unloading – it *often* works,
sometimes doesn't. But still, it's an useful tool that can be often

> You can get the same problems when reverting changes to any resource
> with a shared name: aliases, traps, options, widgets. All code that
> ran after the plugin you are attempting could've been affected by the
> value you are reverting.

Ok, but the unloading can still be useful. For example, besides the
MYPROMPT=1..8 use case, I'm also using it often when developing a
plugin, instead of the shell restart. It allows for a quick
unfunction/redeclaration of autoload functions, for example.

> Removing widgets is very likely to break your prompt due to the way
> widgets are commonly hooked. When a decent plugin wants to hook a zle
> widget, it will copy the previous widget and install its own.
> ...
> if *this* widget gets wrapped too, and you remove it, the chain of
> hooks is broken.

This particular case will be solved if the plugin will use
add-zle-hook-widget instead of wrapping (support for this isn't yet in
zplugin, but it'll be there soon).

> > I think that it's actually possible to predict to a large extent by
> > looking at the list of unload-actions.
> You can predict which aliases will be unset and which widgets removed
> but you cannot predict how it will affect shell. Things can break a
> little or a lot. Things may look OK but do damage behind the scenes.

To sum up, your opinion is a mathematical-like proof that:

* You cannot implement an unloading that just works as expected.

While my opinion is a practical-view -like point that:

* You can often get good results with unloading, just try & test it
first with the plugin that you need to unload.

Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

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