djui / alias-tips

An oh-my-zsh plugin to help remembering those aliases you defined once
781 stars 51 forks source link

why are functions excluded? #32

Closed untoreh closed 7 years ago

untoreh commented 7 years ago

I see functions are actively excluded, why is that? sometimes I use functions for better args parsing and sometimes I forget I made them :)

djui commented 7 years ago

iirc functions are not excluded, see https://github.com/djui/alias-tips/blob/master/alias-tips.plugin.zsh#L28 . Is there anything that makes you believe contrary?

It might be that not all function formats/styles are supported, but that would be simply a parsing difficulty i wanted to avoid. But most should be supported and included.

untoreh commented 7 years ago

eh I was looking at the py code sorry

untoreh commented 7 years ago

I tested a little bit, so I do something like

hellofun(){ echo hello }
echo hello
alias hellofun="echo hello"
echo hello
Alias tip: hellofun
hello

does not seem to work?

djui commented 7 years ago

Interesting, good find. Will investigate.

djui commented 7 years ago

I had a more thorough look and yes, it currently does not support functions; not as a bug but as a missing feature. We only use the functions to not do expansion as one might believe they should not get replace.

But to your request, it would be interesting to parse the entire function body and see if their body matches the input. I just assume for most functions this will not apply as they are functions to create multi-line commands. For single line commands it could be interesting.

The problem I see is how to efficiently parse the functions. Usually, with the git aliases and zsh aliases, this is done in the shell script rather than the python script, as it has a high overhead cost spawn a shell to get the function definitions. And I don't want to do trickier multiline parsing in shell as it gets very quickly very brittle.

So I think, as an implementation detail, to make this work, we would have to rewrite the script entirely. If I do this, I will likely change it from Python to Go and move all logic over from the Shell script to the new Go Script. With moving to Go which will come with a binary also comes the challenge of cross-platform support. I could imagine however to just ship both linux and mac binaries and then let the script pick the right one.

And this likely take a while, unfortunately.

untoreh commented 7 years ago

I suppose functions having arguments would require regex, that could being too much of a burden for something that is supposed to run on each command

djui commented 7 years ago

Agree, thats another problem. Besides being one line, they might not take parameters.