From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11453 invoked by alias); 1 Mar 2013 15:07:34 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 31091 Received: (qmail 21233 invoked from network); 1 Mar 2013 15:07:31 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <130301070718.ZM10378@torch.brasslantern.com> Date: Fri, 01 Mar 2013 07:07:18 -0800 In-reply-to: Comments: In reply to Idan Kamara "Leveraging the completion system to discover available options in a command" (Mar 1, 3:23pm) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: Leveraging the completion system to discover available options in a command MIME-version: 1.0 Content-type: text/plain; charset=us-ascii 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.