/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/plugins/bash_completion/bashcomp.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
 
from ... import (
 
21
from bzrlib import (
22
22
    cmdline,
23
23
    commands,
24
24
    config,
26
26
    option,
27
27
    plugin,
28
28
)
29
 
from ...sixish import (
30
 
    text_type,
31
 
    )
32
 
import breezy
 
29
import bzrlib
33
30
import re
34
31
import sys
35
32
 
37
34
class BashCodeGen(object):
38
35
    """Generate a bash script for given completion data."""
39
36
 
40
 
    def __init__(self, data, function_name='_brz', debug=False):
 
37
    def __init__(self, data, function_name='_bzr', debug=False):
41
38
        self.data = data
42
39
        self.function_name = function_name
43
40
        self.debug = debug
44
41
 
45
42
    def script(self):
46
43
        return ("""\
47
 
# Programmable completion for the Breezy brz command under bash.
 
44
# Programmable completion for the Bazaar-NG bzr command under bash.
48
45
# Known to work with bash 2.05a as well as bash 4.1.2, and probably
49
46
# all versions in between as well.
50
47
 
55
52
# Generated using the bash_completion plugin.
56
53
# See https://launchpad.net/bzr-bash-completion for details.
57
54
 
58
 
# Commands and options of brz %(brz_version)s
 
55
# Commands and options of bzr %(bzr_version)s
59
56
 
60
57
shopt -s progcomp
61
58
%(function)s
62
 
complete -F %(function_name)s -o default brz
 
59
complete -F %(function_name)s -o default bzr
63
60
"""     % {
64
61
            "function_name": self.function_name,
65
62
            "function": self.function(),
66
 
            "brz_version": self.brz_version(),
 
63
            "bzr_version": self.bzr_version(),
67
64
        })
68
65
 
69
66
    def function(self):
128
125
        if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
129
126
                case $curOpt in
130
127
                        tag:|*..tag:)
131
 
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
 
128
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
132
129
                                ;;
133
130
                esac
134
131
                case $cur in
135
132
                        [\\"\\']tag:*)
136
 
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
 
133
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
137
134
                                ;;
138
135
                        [\\"\\']*..tag:*)
139
 
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//') )
 
136
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//') )
140
137
                                fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
141
138
                                ;;
142
139
                esac
186
183
        echo -ne '---\e[K\e[u'
187
184
""")
188
185
 
189
 
    def brz_version(self):
190
 
        brz_version = breezy.version_string
 
186
    def bzr_version(self):
 
187
        bzr_version = bzrlib.version_string
191
188
        if not self.data.plugins:
192
 
            brz_version += "."
 
189
            bzr_version += "."
193
190
        else:
194
 
            brz_version += " and the following plugins:"
195
 
            for name, plugin in sorted(self.data.plugins.items()):
196
 
                brz_version += "\n# %s" % plugin
197
 
        return brz_version
 
191
            bzr_version += " and the following plugins:"
 
192
            for name, plugin in sorted(self.data.plugins.iteritems()):
 
193
                bzr_version += "\n# %s" % plugin
 
194
        return bzr_version
198
195
 
199
196
    def global_options(self):
200
197
        return " ".join(sorted(self.data.global_options))
263
260
    def __init__(self, name, version=None):
264
261
        if version is None:
265
262
            try:
266
 
                version = breezy.plugin.plugins()[name].__version__
 
263
                version = bzrlib.plugin.plugins()[name].__version__
267
264
            except:
268
265
                version = 'unknown'
269
266
        self.name = name
299
296
        elif selected_plugins is None:
300
297
            self.selected_plugins = None
301
298
        else:
302
 
            self.selected_plugins = {x.replace('-', '_')
303
 
                                         for x in selected_plugins}
 
299
            self.selected_plugins = set([x.replace('-', '_')
 
300
                                         for x in selected_plugins])
304
301
 
305
302
    def collect(self):
306
303
        self.global_options()
317
314
                self.data.global_options.add(short)
318
315
 
319
316
    def aliases(self):
320
 
        for alias, expansion in config.GlobalConfig().get_aliases().items():
 
317
        for alias, expansion in config.GlobalConfig().get_aliases().iteritems():
321
318
            for token in cmdline.split(expansion):
322
319
                if not token.startswith("-"):
323
320
                    self.user_aliases.setdefault(token, set()).add(alias)
355
352
            if useralias not in cmd_data.aliases]))
356
353
 
357
354
        opts = cmd.options()
358
 
        for optname, opt in sorted(opts.items()):
 
355
        for optname, opt in sorted(opts.iteritems()):
359
356
            cmd_data.options.extend(self.option(opt))
360
357
 
361
358
        if 'help' == name or 'help' in cmd.aliases:
376
373
            if enum_data:
377
374
                try:
378
375
                    enum_data.registry_keys = opt.registry.keys()
379
 
                except ImportError as e:
 
376
                except ImportError, e:
380
377
                    enum_data.error_messages.append(
381
378
                        "ERROR getting registry keys for '--%s': %s"
382
379
                        % (opt.name, str(e).split('\n')[0]))
398
395
        return self.wrap_container(optswitches, parser)
399
396
 
400
397
 
401
 
def bash_completion_function(out, function_name="_brz", function_only=False,
 
398
def bash_completion_function(out, function_name="_bzr", function_only=False,
402
399
                             debug=False,
403
400
                             no_plugins=False, selected_plugins=None):
404
401
    dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
419
416
    the completion key (usually tab).
420
417
    
421
418
    Commonly used like this:
422
 
        eval "`brz bash-completion`"
 
419
        eval "`bzr bash-completion`"
423
420
    """
424
421
 
425
422
    takes_options = [
426
 
        option.Option("function-name", short_name="f", type=text_type, argname="name",
427
 
               help="Name of the generated function (default: _brz)"),
 
423
        option.Option("function-name", short_name="f", type=str, argname="name",
 
424
               help="Name of the generated function (default: _bzr)"),
428
425
        option.Option("function-only", short_name="o", type=None,
429
426
               help="Generate only the shell function, don't enable it"),
430
427
        option.Option("debug", type=None, hidden=True,
431
428
               help="Enable shell code useful for debugging"),
432
 
        option.ListOption("plugin", type=text_type, argname="name",
 
429
        option.ListOption("plugin", type=str, argname="name",
433
430
                # param_name="selected_plugins", # doesn't work, bug #387117
434
431
                help="Enable completions for the selected plugin"
435
432
                + " (default: all plugins)"),
458
455
 
459
456
    parser = optparse.OptionParser(usage="%prog [-f NAME] [-o]")
460
457
    parser.add_option("--function-name", "-f", metavar="NAME",
461
 
                      help="Name of the generated function (default: _brz)")
 
458
                      help="Name of the generated function (default: _bzr)")
462
459
    parser.add_option("--function-only", "-o", action="store_true",
463
460
                      help="Generate only the shell function, don't enable it")
464
461
    parser.add_option("--debug", action="store_true",
465
462
                      help=optparse.SUPPRESS_HELP)
466
463
    parser.add_option("--no-plugins", action="store_true",
467
 
                      help="Don't load any brz plugins")
 
464
                      help="Don't load any bzr plugins")
468
465
    parser.add_option("--plugin", metavar="NAME", type="string",
469
466
                      dest="selected_plugins", default=[],
470
467
                      action="callback", callback=plugin_callback,
474
471
    if args:
475
472
        parser.error("script does not take positional arguments")
476
473
    kwargs = dict()
477
 
    for name, value in opts.__dict__.items():
 
474
    for name, value in opts.__dict__.iteritems():
478
475
        if value is not None:
479
476
            kwargs[name] = value
480
477