/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

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 bzrlib import (
 
21
from ... import (
22
22
    cmdline,
23
23
    commands,
24
24
    config,
26
26
    option,
27
27
    plugin,
28
28
)
29
 
import bzrlib
 
29
import breezy
30
30
import re
31
31
import sys
32
32
 
34
34
class BashCodeGen(object):
35
35
    """Generate a bash script for given completion data."""
36
36
 
37
 
    def __init__(self, data, function_name='_bzr', debug=False):
 
37
    def __init__(self, data, function_name='_brz', debug=False):
38
38
        self.data = data
39
39
        self.function_name = function_name
40
40
        self.debug = debug
41
41
 
42
42
    def script(self):
43
43
        return ("""\
44
 
# Programmable completion for the Bazaar-NG bzr command under bash.
 
44
# Programmable completion for the Breezy brz command under bash.
45
45
# Known to work with bash 2.05a as well as bash 4.1.2, and probably
46
46
# all versions in between as well.
47
47
 
52
52
# Generated using the bash_completion plugin.
53
53
# See https://launchpad.net/bzr-bash-completion for details.
54
54
 
55
 
# Commands and options of bzr %(bzr_version)s
 
55
# Commands and options of brz %(brz_version)s
56
56
 
57
57
shopt -s progcomp
58
58
%(function)s
59
 
complete -F %(function_name)s -o default bzr
 
59
complete -F %(function_name)s -o default brz
60
60
"""     % {
61
61
            "function_name": self.function_name,
62
62
            "function": self.function(),
63
 
            "bzr_version": self.bzr_version(),
 
63
            "brz_version": self.brz_version(),
64
64
        })
65
65
 
66
66
    def function(self):
125
125
        if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
126
126
                case $curOpt in
127
127
                        tag:|*..tag:)
128
 
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
 
128
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/ /\\\\\\\\ /g;') )
129
129
                                ;;
130
130
                esac
131
131
                case $cur in
132
132
                        [\\"\\']tag:*)
133
 
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
 
133
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//; s/^/tag:/') )
134
134
                                ;;
135
135
                        [\\"\\']*..tag:*)
136
 
                                fixedWords=( $(bzr tags 2>/dev/null | sed 's/  *[^ ]*$//') )
 
136
                                fixedWords=( $(brz tags 2>/dev/null | sed 's/  *[^ ]*$//') )
137
137
                                fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
138
138
                                ;;
139
139
                esac
183
183
        echo -ne '---\e[K\e[u'
184
184
""")
185
185
 
186
 
    def bzr_version(self):
187
 
        bzr_version = bzrlib.version_string
 
186
    def brz_version(self):
 
187
        brz_version = breezy.version_string
188
188
        if not self.data.plugins:
189
 
            bzr_version += "."
 
189
            brz_version += "."
190
190
        else:
191
 
            bzr_version += " and the following plugins:"
 
191
            brz_version += " and the following plugins:"
192
192
            for name, plugin in sorted(self.data.plugins.iteritems()):
193
 
                bzr_version += "\n# %s" % plugin
194
 
        return bzr_version
 
193
                brz_version += "\n# %s" % plugin
 
194
        return brz_version
195
195
 
196
196
    def global_options(self):
197
197
        return " ".join(sorted(self.data.global_options))
260
260
    def __init__(self, name, version=None):
261
261
        if version is None:
262
262
            try:
263
 
                version = bzrlib.plugin.plugins()[name].__version__
 
263
                version = breezy.plugin.plugins()[name].__version__
264
264
            except:
265
265
                version = 'unknown'
266
266
        self.name = name
296
296
        elif selected_plugins is None:
297
297
            self.selected_plugins = None
298
298
        else:
299
 
            self.selected_plugins = set([x.replace('-', '_')
300
 
                                         for x in selected_plugins])
 
299
            self.selected_plugins = {x.replace('-', '_')
 
300
                                         for x in selected_plugins}
301
301
 
302
302
    def collect(self):
303
303
        self.global_options()
373
373
            if enum_data:
374
374
                try:
375
375
                    enum_data.registry_keys = opt.registry.keys()
376
 
                except ImportError, e:
 
376
                except ImportError as e:
377
377
                    enum_data.error_messages.append(
378
378
                        "ERROR getting registry keys for '--%s': %s"
379
379
                        % (opt.name, str(e).split('\n')[0]))
395
395
        return self.wrap_container(optswitches, parser)
396
396
 
397
397
 
398
 
def bash_completion_function(out, function_name="_bzr", function_only=False,
 
398
def bash_completion_function(out, function_name="_brz", function_only=False,
399
399
                             debug=False,
400
400
                             no_plugins=False, selected_plugins=None):
401
401
    dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
416
416
    the completion key (usually tab).
417
417
    
418
418
    Commonly used like this:
419
 
        eval "`bzr bash-completion`"
 
419
        eval "`brz bash-completion`"
420
420
    """
421
421
 
422
422
    takes_options = [
423
423
        option.Option("function-name", short_name="f", type=str, argname="name",
424
 
               help="Name of the generated function (default: _bzr)"),
 
424
               help="Name of the generated function (default: _brz)"),
425
425
        option.Option("function-only", short_name="o", type=None,
426
426
               help="Generate only the shell function, don't enable it"),
427
427
        option.Option("debug", type=None, hidden=True,
455
455
 
456
456
    parser = optparse.OptionParser(usage="%prog [-f NAME] [-o]")
457
457
    parser.add_option("--function-name", "-f", metavar="NAME",
458
 
                      help="Name of the generated function (default: _bzr)")
 
458
                      help="Name of the generated function (default: _brz)")
459
459
    parser.add_option("--function-only", "-o", action="store_true",
460
460
                      help="Generate only the shell function, don't enable it")
461
461
    parser.add_option("--debug", action="store_true",
462
462
                      help=optparse.SUPPRESS_HELP)
463
463
    parser.add_option("--no-plugins", action="store_true",
464
 
                      help="Don't load any bzr plugins")
 
464
                      help="Don't load any brz plugins")
465
465
    parser.add_option("--plugin", metavar="NAME", type="string",
466
466
                      dest="selected_plugins", default=[],
467
467
                      action="callback", callback=plugin_callback,