0

I did this. Then the completion candidate is displayed like this,

$ foo() { COMPREPLY=($(compgen -W "abc def ghi" -- "$2")); }
$ complete -E -F foo
$ (two times tab key)
abc  def  ghi
$

And I thought that abc would be complemented by the following:

$ ab (presstab key)

However, commands that start with ab actually appear as completion candidates.

$ ab (two times tab key)
ab                                   abrt-action-save-package-data
abrt-action-analyze-backtrace        abrt-action-trim-files
abrt-action-analyze-c                abrt-auto-reporting

In man bash, indeed, the -E option indicates that the remaining options and behavior apply to "empty" command completion (completion attempted on blank lines).

It says that only when it is "empty" is as described, but there is no use for the -E option. Also, it seems that there is no way to do completion other than command name completion when the command is not yet recognized like "ab tab twice" above.

Is this something we can't do anymore, or is there something overlooked?

  • The behaviour makes sense in that once you have a non-empty line, you probably want to complete an existing command, no? `abc`, `def`and `ghi` would correspond to existing commands with their own completions in place, so `abc` would still show up for the non-empty line. What's your specific use case? – Benjamin W. Jan 23 '20 at 14:41
  • Does this answer your question? [Bash programmable completion when typing "first command"](https://stackoverflow.com/questions/10450289/bash-programmable-completion-when-typing-first-command) – Armali Jan 23 '20 at 15:19

0 Answers0