0

I'm working on a tool that analyzes CLI tools part of which requires analyzing tab completions

I know how to run a command like so

out, err := exec.Command("git").Output()
if err != nil {
    log.Fatal(err)
}
fmt.Printf("The date is %s\n", out)

but how would I get the tab completions for that command programmatically? I want to be able to programmatically see the completions that would be listed from git <tab>

Bonus points if you know how to hook into zsh completions!

Chris W
  • 785
  • 8
  • 18
  • 1
    `git` doesn't know anything about completions; this is done by the shell (bash, zsh, fish, tcsh, etc.) which use (sometimes extensive) configurations for this to figure our what can be completed where. The [zsh git completion](https://sourceforge.net/p/zsh/code/ci/master/tree/Completion/Unix/Command/_git) is not exactly simple. You could perhaps start a new `zsh`, make sure completion is set up, and feed it commandline + `^D`/``, but it all sounds pretty ugly to me. What is the problem you want to solve? – Martin Tournoij Jan 14 '21 at 11:00
  • @MartinTournoij So I'm working on this tool https://github.com/chriswalz/bit. The problem is the suggestions that show up in the animation have all been added by hand (effectively through copy paste). If I could tap into the completions programmatically and then create a completion tree data structure (see the data structure here: https://github.com/chriswalz/bit/commit/da623d9730f360f9ddd2585f5602e3a9eea51c22), I could then have completions for all git commands, flags – Chris W Jan 15 '21 at 01:41

0 Answers0