bash-completion icon indicating copy to clipboard operation
bash-completion copied to clipboard

Use `sudo` with `complete -C` commands

Open cykerway opened this issue 4 years ago • 1 comments

Describe the bug

When a command is completed with complete -C, sudo complete is not working.

To reproduce

$ complete -C 'echo' foo
$ sudo foo <tab>

Gives warning:

-bash: compgen: warning: -C option may not work as you expect

Expected behavior

No warning message thrown, and sudo foo completes the same way as foo.

Versions (please complete the following information)

  • [linux] Operating system name/distribution and version:
  • [5.1] bash version, echo "$BASH_VERSION":
  • [2.11] bash-completion version, (IFS=.; echo "${BASH_COMPLETION_VERSINFO[*]}"):

Additional context

man bash says about compgen:

When using the -F or -C options, the various shell variables set by the programmable completion facilities, while available, will not have useful values.

_command_offset knows about -F but not -C:

...
if [[ ${cspec#* -F } != "$cspec" ]]; then
...

Debug trace

cykerway avatar Oct 19 '21 15:10 cykerway

This seems to be a dependency of https://github.com/cykerway/complete-alias/issues/30, which uses _command_offset.

cykerway avatar Oct 19 '21 15:10 cykerway