scop / bash-completion

Programmable completion functions for bash
GNU General Public License v2.0
2.9k stars 380 forks source link

feat(env): complete commands and variable assignments #1118

Closed scop closed 6 months ago

scop commented 7 months ago

Refs https://github.com/scop/bash-completion/issues/1111

scop commented 7 months ago

Test coverage is likely something to expand before we merge this.

Would be nice to also address --*-signal=SIG too, but that's not a blocker I think.

akinomyoga commented 6 months ago

I added further commits because -* may also be treated as the command name after any variable assignments *=*. For example, in the case of env foo=bar --debug s, --debug is actually treated as the command name by env. Commit 71b7fb2bc handles it.

However, I noticed that if we pass the position of --debug to _comp_command_offset, _comp_load produces error messages because it internally checks the command name by type -P "$cmd". So I first fixed _comp_load (and _comp_realcommand, which uses type -P in a similar way) in commit 883946d84.

In addition, after the option -- and -, any non-variable-assignment word (including -*) is treated as the command name. Commit 0cd2883ca implements the handling of these.

akinomyoga commented 6 months ago

Thanks!

There are actually similar cases for type -P, but I think we should consider them in another PR.