-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autocomplete #289
Comments
This has to be done by the terminal/os and is pretty fiddly, which is why I've hesitated to take on that maintenance burden. |
I'm currently using the zsh
here's the script to do Makefile completion https://github.com/zsh-users/zsh/blob/master/Completion/Unix/Command/_make The only burden Mage has over Make is identifying mage files. But since that's already defined as:
It only means that parsing many files in the repo root would be needed. I think parsing the first 10 lines of file would probably be enough to identify which files are mage files or not, for performance reasons. |
I also found this that might make it easier: |
oh, target imports would also be another burden, though it's explained here: |
@natefinch could you point me at a method that would return a list of targets? I can see if I can submit a PR for this. |
It seems I could write something fairly simple, at least for The problems I see right now are that Additionally, it's not required that Related situations to this I found: In order to solve the performance problem, we could leverage the compiled binary if it exists, but since the name of that binary is unknown, and could likely change from project to project (even on the same developer machine), we'd need the global |
for the time being though, the autocomplete script could do something like this: if [ -x ./mage ]; then
out=$(./mage -l)
else
out=$(mage -l)
fi
echo "${out}" | tail -n +2 | awk '{ print $1 }' This makes some assumptions though that cannot be easily controlled by the user. |
so looking at this more, completions, though folks have said is a "simple dsl" is hard to wrap my mind around. I'm wondering if instead, mage switched to using https://github.com/spf13/cobra which supports generating completions for zsh and bash natively. |
so, I figured out the script, naively assuming that the built binary is
So, to make this work for both a binary and not, I think there needs to be some way of knowing what the binary name is, such as an environment variable. If that's not present, fallback to running @natefinch thoughts on this? |
haha, just found out that
|
I haven't used it yet but https://github.com/iwittkau/mage-select offers bash completion, worth looking into I reckon |
Downside is this also uses But if its include in Mage and |
#113 has some completion scripts which might solve this one |
I've asked a related question on #368 I was thinking of generating some vscode tasks, but also have thought about integration https://github.com/c-bata/go-prompt. I'm thinking of:
Some prompt action like the bit cli would be pretty awesome if we can figure it out. |
There is an alternative approach where you use the binary to generate completions directly. You can handle all your completions in Go and just detect if bash is calling the go binary in completion mode or in execution mode. Once you do that you actually get built in completions that are never out of date. I have a Youtube video with my CLI parser which does just that, but the same approach can be adapted to leverage the existing CLI parser mage is using. |
Having |
Any traction on this? |
bumping, anyone ever get something going on their machine? |
Since I've started using Mage as an actual Bash replacement and I'm defining large number of targets-as-commands with variety of arguments, and aliases too, I'm thankful for the awesome Would you indeed agree that the best approach seems to be that Mage could generates the completion itself?
correct? Any disadvantages of making the one or the other Mage's dependency? |
Mage development has stalled to my knowledge due to other priorities from the original creator. Still great to use as is but I doubt you'll see significant features until that changes. Try Mage-select. It's a great alternative to invoking interactively. |
I'm sad to say I have noticed. I still hope future of Mage is bright - I love it.
Yeah, I am going to, definitely. |
Would be great if you could type
mage
and press tab to autocomplete all the possible commands. Or start typing commandmage st
and on tab it would autocomplete to the nearest matching command.Is it possible to add this to mage itself or it has to be added in some other way?
The text was updated successfully, but these errors were encountered: