felix rosencrantz Generating Screen Completion
process
Using perl and XML I've been attempting to automatically (or semi-automatically) generate ZSH completion functions.

Here I've created a much  simpler XML schema to  make it easier to generate XML that describes the "screen" command.  This simpler XML format is then converted via XSLT to the full completion XML schema.

If I can make a tool out of the usage information to simple XML it should be possible with little effort to create semi-useful completion functions quickly.

Even with the automation, to get a more usable completion function required me to hand edit the generated  simple XML and definitions the XSL.  I had to write some ZSH code to generate a list of sessionnames. 

Though overall, I was to create a basic completion function.  Even though there was some hand editing involved,  it was much easier than generating it by hand.

For the steps involving hand edits it would be useful if this might be done via the command line somehow.  It seems that doing something similar to vared, where you have existing content to edit, along with help from the completion system could be very powerful.

step 1 Get the usage information screen.  We are only interested in the flags.

screen -help | grep "^-" > screen.help

We use grep to just pull the lines that contain flags.

step 2

Convert the flag help into PYX, a line oriented version of XML.

help2simple.pl screen.help > simple_screen.pyx

The PYX format is easier to generate than XML proper, since there is less need to make sure everything is closed.  Originally help2simple.pl was a single line perl script, placed on the command line, so PYX was useful for that. 

step 3

Now convert the PYX format to the simple xml completion format:

pyxw simple_screen.pyx > screen_simple.xml

There is a perl library called XML::PYX that contains the utility pyxw.  I made some small edits to that script to make the output a little more human readable.

Looking at this simple XML format is much easier to read than the longer format.  Most details about a flag are provided as attributes.  For non basic information, content is in the format of the longer completion xml format, and are placed as child nodes of the flag element.

I'm still working on what this simple format should look like.  So it is likely to under go many more changes to clean it up and add functionality (hopefully without adding too much complexity or verbosity.)

step 4 Now perform hand edits to make the generated completion function more useful.

The edits I performed where as follows:

  • Remove bogus argtags for -[AdD]
  • Modified -X.
  • Changed argtag to sessionname for -d
  • Changed taghelp for -d to mention -r flag.
  • Removed multiple flag elements for -D flag.
  • Change taghelp for -D to mention -r flag
  • Remove mention of '-ls; in help for -list flag
  • Add -ls flag <flag> element. (Duplciate of -list)
  • For <flag -f> add modifier that says flag arg must be in the same word
  • For <flag -f> add fixed_set w/help as action.
  • For <flag -r> add sessionname argtag.
  • Add <flag -X> add argtag screencmd
     

The resulting file was simple_editted.xml.

step 5 Generate the XML format that describes a completion function:

java jd.xml.xslt.Stylesheet simple_editted.xml simple2long.xsl > screen.xml

I'm using a new XSLT processor called jd.xslt.

The simple2long.xsl script takes the simple format and generates the longer format.  Changes to the simple format will have to be reflected in this script.

step 6 Now we need to generate the definitions for action templates.  This will be used by arg.xsl when generating the completion function.

java jd.xml.xslt.Stylesheet screen.xml gen_comdefs.xsl unique_actions.xsl > screen_defines.xml

step 7 Hand edit the screen_defines.xml file.  The edits made were to add actions or list for the following tags:
  •  file --> _files
  • sessionname -> Wrote some state code
  • screencmd -> created a list of commands from the man page, generated a fixed string list.

The resulting output was screen_defines.xml
 

step 8 Now generate the completion function.

java jd.xml.xslt.Stylesheet screen.xml arg.xsl > _screen

The unformatted version of the file _screen.

future Additional things that should be done or can be done:
  • Clean up the completion function.  This function is not correct.  For example:
    • The -X flag takes the rest of the command line arguments.
    • Some flags can be listed multiple times.
    • There are some exclusionlists that can be added.
  • Convert the completion for the -X flag, to handle completions for the screen commands.  The long XML completion format has support for subcommands (see the clearcase completion).
  • Improve the simple XML completion format to handle simple things like exlusion lists, and easier to say if a flag can be used mutiple times.
  • The long completion format doesn't describe GNU style _arguments.  This support should be added.
  • Create a DTD for the simple xml  format.

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