MestreLion / git-tools

Assorted git tools, including git-restore-mtime
GNU General Public License v3.0
292 stars 75 forks source link

Add bash completion scripts #66

Open Chairn opened 11 months ago

Chairn commented 11 months ago

Hello,

It would be nice to have bash auto complete either files or command just like any other git commands. I tried to look at git-completions, but it's hard to understand how it works.

By default, on Debian 12, "git rest" autocomplete to "git restore " and not "git restore" which means we have to backtrack one character (the space after restore) and then type "-mtime" manually. Afterwards, no completion occurs, neither for files nor for options.

I don't know if it's easily doable. Thanks

MestreLion commented 9 months ago

There are 2 "tiers" of bash-completion for git: the easy one, that simply completes the subcommand, so git rest<TAB> expands to git restore-mtime. And the tricky one, that autocompletes arguments based on current subcommand.

The former already works, provided you've installed git-restore-mtime anywhere in your $PATH. git itself does that for all available subcommands, nothing required on my part.

The latter would require actual implementation on my part, it's in my TO-DO list but I don't believe I'll do it in the near (or even mid) future.

However, I know there are tools to auto-generate bash-completions based on --help output, and some for Python scripts that use argparse (as is the case of git-restore-mtime that are even more accurate than --help parsing. This way anyone can have bash-completions for any command without any intervention or support on the command's part. This could be a workaround until someone PR an actual support.

MestreLion commented 9 months ago

Btw, it seems git restore is a new, experimental command, which I don't have here. Maybe its existence is messing with git's own subcommand completion mechanism?