C console application automatically populates dynamic arguments

I'm looking for an auto-end console method - for example, for an application like:

int main (int argc, char ** argv)
{
  if (argc == 1) return EXIT_FAILURE;
  if (strcmp(argv[1], "good")==0) printf("good\n");
  if (strcmp(argv[1], "bad")==0) printf("bad\n");
  return EXIT_FAILURE;
}

At startup, I would like to press [tab] after the command so that it gives me one of the possible useful parameters.

Example:

./a.out g[tab]

will be completed automatically before

./a.out good

I do not want to edit / etc / bash-completion.d /, I was hoping for a much stronger autocomplete, something like a function of the executable file itself that would be called - perhaps this could query the database for a list of possible options. Or perhaps a message is displayed letting you know what options are.

If you think this is just completely impossible, let me know!

+3
source share
2 answers

- , . , (bash, zsh, tcsh fish ). (, you_application --list-possible-arguments) , , - "" .

bash complete . /etc/completion.d (gpg - , git ).

+2

BASH, :

================================

, Readline:

GNU Readline , . Emacs vi . Readline , , , csh-like .

0

All Articles