felix rosencrantz xml zsh completion
introduction
This page describes a personal project I've been working on to automatically generate completion functions (particularly for zsh) using XML.

Currently I have some tools in perl and XSLT, that will convert Unix command style help (i.e. text from a --help flag) into an  XML format which can be transformed into a usable zsh completion function.  There is still quite a bit of work to do.  But currently it is usable out of the box, though the documentation might be wanting.

A common XML format allows for the creation of other tools that  parse usage information, getopt input, man pages, and other sources of command flag information and convert them into the XML format.  The XML format is then easily transformed into a completion function.

index Downloads  -- tarball containing tools.

History - My experiments.  I drive this project by taking sample commands (e.g. clearcase, screen) and see what I need to do to generate completion functions for them.

Screenshot - Not yet...  Sort of silly since this is a command line tool.  Though, sometimes it helps.

Links - Related tools. (xslt, perl, bash, zsh, tcsh )

Limitations - Stuff that won't be automatically generated.

Documentation - Simple man page for help2simple.pl Also, look at the examples.

FAQ -  Not yet..  Haven't been a lot of questons.

history / examples Since I'm still trying to figure out what format this XML specification should take.  I've attempted to use the format I've suggested to create completion functions.  Below are my first attempts at generating completion functions using XML.  The attempts list the commands I ran with some explanations of what I was doing.
  • clearcase -- completion function for cleartool command.
  • screen -- completion function for the GNU screen command.
  • larch -- completion function for the Tom Lord's arch SCM system.

After feedback from the zsh-workers mailing list, and my own usage.   I needed an XML format that was simpler to use.  I created a new simpler format, that I simply call "simple" as opposed to "long".  The simple format is not as complete as the "long" format, but it handles a good portion of what is needed.  I'm able to generate this new simple format via the "help2simple.pl" script.   For details on usage see help2simple.

 

limitations I believe it will be possible to automate much of the mundane part of generating completion functions for commands from parsing usage information and man pages.

Though I don't think it will be possible to automate the creation of special functions that perform calls to compadd.  This is one thing that won't be possible to automate.  If this XML representation catches on, it might motivate the creation of utility functions that provide wrappers to compadd.  These utility functions might take a command that provides a listing output, and maybe some parsing rules, and call compadd with the correct list of choices.

There is information that may not be clearly provided in usage information that would require some hand tweaking of the XML descriptions.

problems List of problems with the XML completion specification:
  • No way to say certain flags should be used together
  • No way to specify minimum or maximum number of times a flag was used.
  • No ability to specify abbreviations.

 

links
Related tools:

help2man -- A perl script that parses help output to create a man page.  This script handles flag help text spans multiple lines.  It also parses out the leading usage message, and section titles.  Some of these features would be useful to add to help2simple.pl.

Getopt::Declare Declaratively Expressed Command-Line Arguments via Regular Expressions.  With this perl module the user specifies getopt via a help syntax.  I haven't used this module.  Though it seems, that the help has to be in the special format, which is relatively free format.  It would be great if this library could output a data structure that could be used by help2simple.pl

parse_opts Arguments processing tool by Martin Ebourne.  Designed as both a completion tool and the command line parsing tool.

clo++ command line option  parser generator, using an XML specification.

AutoOpts -- command line option parser, using a flat file specification.

Tools Used:

xslt -  W3C technical report, Home page.

XSLT processors:  xsltproc, jd.xslt, saxon, xalan.

Shells:

zsh, tcsh, bash

Heiner's SHELLdorado -- interesting site devoted to unix shells.

XSH XML Editing Shell -- looks like a useful XML shell.  Includes things like xslt and  xupdate.  Plus the ability to work with shell commands.

ZSH Shell:

zsh -- Zsh home page

Z-shell user guide -- More tutorial style documenation.

Introduction to ZSH completion -- From the User Guide

Switching to zsh from other shells

Completion:

bash programmable completion project - by Ian MacDonald.  Project to write completion functions for bash.  (The freshmeat project page mentions this site.)

 


Web site Copyright ©  2001 Felix Rosencrantz, f_rosencrantz@yahoo.com