bzr shell completion

Clint Adams schizo at debian.org
Tue Oct 18 18:59:59 BST 2005


> I've just merged in the small zsh shell completion function from Clint
> Adams, which lets zsh complete bzr command names.  The shell-complete
> command ought to also allow completers to show a list of valid options
> for any command.
> 
> The change to define options by arguments should make it easy for
> shell-complete to describe which options take arguments, and what
> arguments are allowed.  We might need to add more specificity to some
> option objects.

This is not much of an improvement, especially without the appropriate
code in _bzr.  Things that should happen:

1) More specificity, either in "type" or another field; "str" and
   "unicode" aren't very useful from a completion standpoint.

2) Do something about takes_args, or specify argument type somewhere.

3) Generate "(merge3 diff3)" dynamically from merge_types?

4) Figure out potential completions for "revision string" arguments.
   I'm not familiar enough with bzr to know how to do this.

5) Put the remaining code into _bzr.

=== modified file 'bzrlib/shellcomplete.py'
--- bzrlib/shellcomplete.py
+++ bzrlib/shellcomplete.py
@@ -29,7 +29,7 @@
 
 
 def shellcomplete_on_option(options, outfile=None):
-    from bzrlib.option import Option
+    from bzrlib.option import Option, _parse_revision_str, _parse_merge_type
     if not options:
         return
     if outfile == None:
@@ -38,9 +38,21 @@
         for shortname, longname in Option.SHORT_OPTIONS.items():
             if longname == on:
                 l = '"(--' + on + ' -' + shortname + ')"{--' + on + ',-' + shortname + '}'
-                break
+		break
 	    else:
 		l = '--' + on
+
+        if Option.OPTIONS[on].type == None:
+	    continue
+        if Option.OPTIONS[on].type == str:
+	    l += ':str'
+        if Option.OPTIONS[on].type == unicode:
+	    l += ':unicode'
+        if Option.OPTIONS[on].type == _parse_revision_str:
+	    l += ':"rev str"'
+        if Option.OPTIONS[on].type == _parse_merge_type:
+	    l += ':"merge type:(merge3 diff3)"'
+
         outfile.write(l + '\n')
 
 





More information about the bazaar mailing list