Giter Club home page Giter Club logo

Comments (16)

romkatv avatar romkatv commented on June 26, 2024 1

Personally, I don’t mind. Do you?

I've opened this issue because automatic alias expansion looks like an important enough effect to warrant a mention in the docs. It's an odd thing to bundle with formatting.

Note that alias expansion can change the effect of typed commands. For example:

% alias echo='echo foo'
% echo bar

Normally this will print "foo bar" but with automatic formatting it'll print "foo foo bar".

There are also more obscure cases where automatic formatting introduces side effects. For example, try executing the following command:

: }; touch foo; () { :

Without automatic formatting this command fails to parse and does nothing. With automatic formatting it touches file foo.

I don't mind any of it. Feel free to close this issue if or when you find it appropriate. Whatever you decide to do (including nothing at all) is fine with me.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Yeah, I know. It’s a side effect of using $functions to format the code. Personally, I don’t mind. Do you?

As a workaround, you can disable automatic code formatting with

add-zle-hook-widget -d line-finish .hist.format.hook

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Actually, I just realized it’s a side effect of using eval. I’ll see if I can work around it/not use eval for this.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

setopt localoptions NO_aliases should probably do the trick. I’ll have to test it.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Thanks for the detailed motivation. After reading this, I definitely want to fix it. It threw me off guard, too, the first time the alias expansion happened to me.

There are also more obscure cases where automatic formatting introduces side effects. For example, try executing the following command:

: }; touch foo; () { :

Without automatic formatting this command fails to parse and does nothing. With automatic formatting it touches file foo.

Ah, that’s nasty. I’ll definitely have to see if I can fix that. It probably won’t come up often, but it looks like it can have seriously bad side effects.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Problem solved.

from zsh-hist.

romkatv avatar romkatv commented on June 26, 2024

I took a look at the fix. There are still corner cases where enabling auto-formatting will change the effect of commands. Example:

% alias -g ';'=
% echo foo; echo bar

Without automatic formatting this prints "foo echo bar". With automatic formatting it prints "foo" and "bar".

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Is there a real use case for a global alias like that?

from zsh-hist.

romkatv avatar romkatv commented on June 26, 2024

Is there a real use case for a global alias like that?

I don't know. Does it matter?

It would be useful to provide the following guarantee:

  • Automatic formatting never changes the meaning of commands.

When you put it this way, it would appear very surprising if this guarantee weren't provided. Yet there are many violations of this guarantee right now. I've posted one example above. Here's another:

% emulate zsh -o extended_glob
% echo '
do
'

With automatic formatting the last command is rewritten to this:

echo '; do
'

The usual disclaimer applies: I don't have a personal preference one way or another. It's fine with me if you do nothing or change the code in any way you like.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Hm, that last example is definitely a bug. I think I'll have to change my approach on how to implement this.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

Is there a real use case for a global alias like that?

I don't know. Does it matter?

Yes, that matters. It's a cost-benefit analysis: If there's no way this is going to bother anyone, then there's no value in fixing it. It's not worth it to spend time on things that don't benefit anyone.

from zsh-hist.

romkatv avatar romkatv commented on June 26, 2024

It’s not something I want to argue about.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

OK, I pushed in another fix. This should take care of everything except the global ; alias thing.

from zsh-hist.

romkatv avatar romkatv commented on June 26, 2024

The guarantee I’ve mentioned above is still not provided even in the environment without aliases. Unfortunately, I’ve run out of goodwill to post more test cases. You’ll probably find them easily if you look at the code with the intent of seeing the bugs in it.

from zsh-hist.

marlonrichert avatar marlonrichert commented on June 26, 2024

@romkatv Patches welcome.

from zsh-hist.

romkatv avatar romkatv commented on June 26, 2024

I don’t know how to implement automatic parsing without changing the effect of entered commands. At the same time I think it crazy to use a plugin that can change the effect of typed commands in unspecified circumstances. I’ve opened this issue in case you find the information useful.

from zsh-hist.

Related Issues (18)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.