[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Leveraging the completion system to discover available options in a
Re: Leveraging the completion system to discover available options in a command
Sat, 2 Mar 2013 11:17:45 +0100
On Fri, 1 Mar 2013 15:27:31 +0200, Idan Kamara <address@hidden> wrote:
> Is it possible to use the completion system to get a list of available
> options for a command bash knows how to auto-complete?
> Ideally, I'd like given the name of a program to get a list of pairs
> (option string, desc) for each available option. I'd be nice to also
> get options that are only available in a specific context, but given
> how the completion system works, I'd guess that that might be
Bash can't obviously do it itself, but with a custom completion function for
that specific command you can do pretty much anything you want. To see some
examples, install the bash completion package and have a look at the files
that are installed under /etc/bash_completion.d/.
Basically, the completion function parses the current command line (bash
provides some special variables to do that) and understands the current
context, so it can display appropriate completions for the context.