/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 breezy/plugins/bash_completion/bashcomp.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-21 19:09:26 UTC
  • mfrom: (6622.1.36 breezy)
  • Revision ID: jelmer@jelmer.uk-20170521190926-5vtz8xaf0e9ylrpc
Merge rename to breezy.

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 breezy 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
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,