vladimir-kotikov / clink-completions

Completion files to clink util
MIT License
376 stars 81 forks source link

Completions for git aliases #188

Closed narnaud closed 1 month ago

narnaud commented 1 month ago

It would be nice to have completions also for git aliases, when possible.

For example, I have an alias del = branch -D to delete a branch, when I type: git del <Tab> I would expect to see the list of branches. If I type git branch -D <Tab>, it's working as expected.

chrisant996 commented 1 month ago

Alias support already exists, and does completion for flags.

But apparently there is a bug and it doesn't do completion properly for non-flags.

Update: it's working fine for me, actually.

chrisant996 commented 1 month ago

@narnaud what version of clink-completions are you using?

Support for aliases was added in v0.4.0, published on August 25, 2022 (the original commit was 292814ea9841906303807dd4b4c535d19938847b).

Did you create a new alias and immediately try to do completions with it? You would need to reload Clink via Ctrl-X,Ctrl-R to reload the git argmatcher and pick up the new aliases.

chrisant996 commented 1 month ago

Oh, I see. You have an alias which includes flags. That's a whole other complicated problem.

There isn't a way to support that at this time. It's too sophisticated for Clink's argmatcher system, sorry. I'll add it to the wish list for future changes in Clink, and maybe it can happen someday.

narnaud commented 1 month ago

@chrisant996 Thank you for looking at that. For the records, I'm using the latest clink and clink-completions from scoop.

One way to mitigate the issue without doing too many changes and refactoring would be to provide a way for defining how a command completion should behave: ie git del (my alias) should complete like git switch. But it may be too specific to spend time on it...

In the meantime, I've added a branch viewer with fzf where I can delete local branches... so it's less an issue for me.

Thanks for the work, love clink!

chrisant996 commented 1 month ago

One way to mitigate the issue without doing too many changes and refactoring would be to provide a way for defining how a command completion should behave: ie git del (my alias) should complete like git switch.

That's not what you want or need. And anyway that already exists -- that was added in clink-completions v0.4.0, published on August 25, 2022 (the original commit was https://github.com/vladimir-kotikov/clink-completions/commit/292814ea9841906303807dd4b4c535d19938847b). If you have an alias like alias.del=switch (no spaces) then you'll find it already does what you suggested.

The issue is if you have an alias that contains a space, such as your alias.del=branch -D. The space completely changes how parsing needs to happen. Something similar is already done for doskey aliases (see here). But doskey aliases can only be in the first word of a command line, which greatly simplifies the parsing. In order to support how git aliases work, it's necessary to make it so any word anywhere in a command line can be made to switch the parser to temporarily parse a fake partial input line (such as "branch -D"), and then switch back to parsing the rest of the real input line. And don't forget about the ! prefix in git aliases, which requires even more special behaviors.

I know what to do and how to do it. It's just a lot of work.

Your aliases that don't contain spaces should already be fully working.

chrisant996 commented 1 month ago

Update: As of last night, I have some prototype changes in Clink and clink-completions that seem to be working for the "branch -D" example.

I don't have an ETA, though -- there is still much testing and validation to be done. And I plan to support the ! syntax, but I haven't started on that part yet.

chrisant996 commented 1 month ago

Update:

I still need to address a couple quirks, write tests, and write documentation.

Once I'm satisfied, then I'll publish the Clink update, and the clink-completions side will automatically start working as well.

chrisant996 commented 1 month ago

Clink v1.6.18 has been published.

After updating both Clink and clink-completions, git aliases should work very well.