dim-an / cod

cod is a completion daemon for bash/fish/zsh
Apache License 2.0
518 stars 23 forks source link

cod tries to learn commands which already have completions #9

Open zachriggle opened 4 years ago

zachriggle commented 4 years ago

zsh already ships with lots of completion scripts.

cod attempts to learn these, even though they already exist.

For example:

$ git add --help
...
┌──> /usr/local/bin/git add --help
└─── cod: learn this command? [yn?] >

cod should probably check zstyle or compdef to determine which autocompletions are already available.

$ zstyle | grep 'completion.*:git'
        :completion:*:*:git:* common-commands
dim-an commented 4 years ago

It would be nice feature to have but unfortunately it's not that easy to implement.

For now you can use https://github.com/dim-an/cod#configuration. Please check out example configration. You can set up rules to ignore binaries in some paths.

Example of config rule to make cod ignore binaries from /usr/bin/*:

[[rule]]
executable = "/usr/bin/*"
policy = 'ignore'

You can still learn ignored binaries using cod learn -- some-binary --help

dim-an commented 4 years ago

Regarding why I think this feature is not easy.

When I researched how completion is implemented in bash I found out that most of them are loaded lazily, i.e. at the start of the session compdef doesn't show that it knows anything about git. But when you try to complete git command, bash_completion package looks for corresponding completion and loads it.

I didn't looked at zsh, but looks like something similar happens here. Output of zstyle | grep git is empty for me although git have some completions.