zsh-workers
 help / color / mirror / code / Atom feed
* Leveraging the completion system to discover available options in a command
@ 2013-03-01 13:23 Idan Kamara
  2013-03-01 15:07 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Idan Kamara @ 2013-03-01 13:23 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 412 bytes --]

Hi,

Is it possible to use the completion system to get a list of available
options for a command zsh 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
impossible.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Leveraging the completion system to discover available options in a command
  2013-03-01 13:23 Leveraging the completion system to discover available options in a command Idan Kamara
@ 2013-03-01 15:07 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2013-03-01 15:07 UTC (permalink / raw)
  To: zsh-workers

On Mar 1,  3:23pm, Idan Kamara wrote:
}
} Is it possible to use the completion system to get a list of available
} options for a command zsh knows how to auto-complete?

It's for most practical purposes impossible to use the completion system
unless you have an active ZLE $BUFFER to contain the inputs.

Within that constraint, you can create a function wrapper around compadd
that always passes one of the -O or -A options (and probably also -U) to
the builtin compadd whenever one of those options is not already present
in $@, and then invoke the appropriate completion widget with the "zle"
builtin to cause an array that you control to be populated with matches.

However, I don't think that actually addresses your desire:
 
} Ideally, I'd like given the name of a program to get a list of pairs
} (option string, desc) for each available option.

As far as I know there is no way to extract the "display strings" that
are loaded into compadd along with the matches, which would include the
option descriptions.

There is one fairly egregious hack you could employ; copy the technique
from Test/comptest from the zsh sources, which goes something like this:

1. Create a second interactive zsh running on a pseudo-terminal by using
   the zsh/zpty module.

2. Configure the list coloring styles in that copy of zsh to emit strings
   that format the completion list output into something resembling an
   XML structure.

3. Send input through zpty that causes the interactive slave shell to
   perform the completion you want, in list mode.

4. Parse the bits you want from the XML-ish output read with zpty.

You can then erase the command line from the slave shell and keep that
shell around to be able to repeat at (3) without setting up a new pty.
You get to deal with all the possible ways that having a second shell
running commands in the background might go horribly wrong for the user
of the shell in the foreground.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-03-01 15:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-01 13:23 Leveraging the completion system to discover available options in a command Idan Kamara
2013-03-01 15:07 ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).