Merge lp:~benoit.pierre/bzr/shellcomplete into lp:bzr/2.0

Proposed by Benoit Pierre
Status: Merged
Approved by: Ian Clatworthy
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~benoit.pierre/bzr/shellcomplete
Merge into: lp:bzr/2.0
Diff against target: 15 lines
1 file modified
bzrlib/shellcomplete.py (+3/-2)
To merge this branch: bzr merge lp:~benoit.pierre/bzr/shellcomplete
Reviewer Review Type Date Requested Status
Ian Clatworthy Approve
John A Meinel Approve
Review via email: mp+14327@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Benoit Pierre (benoit.pierre) wrote :

Small fix for handling of short option names in shellcomplete_on_options.

Before:

# bzr shell-complete help
"(--usage -None)"{--usage,-None}
"(--verbose -v)"{--verbose,-v}
"(--quiet -q)"{--quiet,-q}
"(--long -None)"{--long,-None}
"(--help -h)"{--help,-h}
topic?

After:

# bzr shell-complete help
--usage
"(--verbose -v)"{--verbose,-v}
"(--quiet -q)"{--quiet,-q}
--long
"(--help -h)"{--help,-h}
topic?

Revision history for this message
John A Meinel (jameinel) wrote :

I don't know the details of what shellcomplete needs, but looking at the change it looks strictly like a correctness change.

Namely, the old check used:

if opt.short_name:

but if short_name is a function, it will always evaluate to true. Which is clearly wrong.

It would be nice to have tests, but this is still a correct patch.

review: Approve
Revision history for this message
John A Meinel (jameinel) wrote :

By the way Benoit, is it possible for you to fill out a contributor agreement:
  http://www.canonical.com/contributors

Revision history for this message
Benoit Pierre (benoit.pierre) wrote :

> By the way Benoit, is it possible for you to fill out a contributor agreement:
> http://www.canonical.com/contributors

Done.

Revision history for this message
Benoit Pierre (benoit.pierre) wrote :

> I don't know the details of what shellcomplete needs, but looking at the
> change it looks strictly like a correctness change.
>
> [...]
>
> It would be nice to have tests, but this is still a correct patch.

I found it because I'm looking into making a better ZSH completer. I don't like the one in contrib because it's too slow: no caching (calls BZR every time), try too hard to be smart (use bzr ls to find unknown/changed/versioned files).

Now the only use of shellcomplete in this version is to call it with no arguments to get the list of commands. Options completion for each commands is hard-coded.

"bzr shell-complete" output format is nice (for ZSH), but "bzr shell-complete command" output format not so much, which might be the reason why nobody seems to be using it.

In fact, the only client so far seems to be the ZSH completer in contrib; the Bash one doesn't use it at all (everything is hardcoded), BzrTools shell command doesn't use it (since in that case it simpler to use the bzrlib API to iterate over commands and their options, I do the same for my VIM plugin).

After hacking a little, I'm starting to think it might be easier to create a small plugin to be able to output in one pass something I can eval inside ZSH.

So far I have a version that separately caches completion options/arguments for each Bazaar command (the first time it's completed).

By now you probably get the point I'm trying to make :) : I think this functionality would be better handled in a separate plugin, with something similar to what has been discussed here: https://lists.ubuntu.com/archives/bazaar/2007q1/022386.html

And looking at the date for this post, the short_name bug has been present for a while...

Revision history for this message
Ian Clatworthy (ian-clatworthy) wrote :

I'll merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/shellcomplete.py'
2--- bzrlib/shellcomplete.py 2009-06-15 11:05:33 +0000
3+++ bzrlib/shellcomplete.py 2009-11-02 22:45:21 +0000
4@@ -47,9 +47,10 @@
5
6 def shellcomplete_on_options(options, outfile=None):
7 for opt in options:
8- if opt.short_name:
9+ short_name = opt.short_name()
10+ if short_name:
11 outfile.write('"(--%s -%s)"{--%s,-%s}\n'
12- % (opt.name, opt.short_name(), opt.name, opt.short_name()))
13+ % (opt.name, short_name, opt.name, short_name))
14 else:
15 outfile.write('--%s\n' % opt.name)
16

Subscribers

People subscribed via source and target branches