50
49
# Generated using the bash_completion plugin.
51
50
# See https://launchpad.net/bzr-bash-completion for details.
53
# Commands and options of brz %(brz_version)s
52
# Commands and options of bzr %(bzr_version)s
57
complete -F %(function_name)s -o default brz
56
complete -F %(function_name)s -o default bzr
59
58
"function_name": self.function_name,
60
59
"function": self.function(),
61
"brz_version": self.brz_version(),
60
"bzr_version": self.bzr_version(),
64
63
def function(self):
66
65
%(function_name)s ()
68
local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
73
cur=${COMP_WORDS[COMP_CWORD]}
76
globalOpts=( %(global_options)s )
78
# do ordinary expansion if we are anywhere after a -- argument
79
for ((i = 1; i < COMP_CWORD; ++i)); do
80
[[ ${COMP_WORDS[i]} == "--" ]] && return 0
83
# find the command; it's the first word not starting in -
85
for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
86
if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
87
cmd=${COMP_WORDS[cmdIdx]}
92
# complete command name if we are not already past the command
93
if [[ $COMP_CWORD -le cmdIdx ]]; then
94
COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
98
# find the option for which we want to complete a value
100
if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
101
curOpt=${COMP_WORDS[COMP_CWORD - 1]}
102
if [[ $curOpt == = ]]; then
103
curOpt=${COMP_WORDS[COMP_CWORD - 2]}
104
elif [[ $cur == : ]]; then
107
elif [[ $curOpt == : ]]; then
108
curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
67
local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
72
cur=${COMP_WORDS[COMP_CWORD]}
75
globalOpts=( %(global_options)s )
77
# do ordinary expansion if we are anywhere after a -- argument
78
for ((i = 1; i < COMP_CWORD; ++i)); do
79
[[ ${COMP_WORDS[i]} == "--" ]] && return 0
82
# find the command; it's the first word not starting in -
84
for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
85
if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
86
cmd=${COMP_WORDS[cmdIdx]}
91
# complete command name if we are not already past the command
92
if [[ $COMP_CWORD -le cmdIdx ]]; then
93
COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
97
# find the option for which we want to complete a value
99
if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
100
curOpt=${COMP_WORDS[COMP_CWORD - 1]}
101
if [[ $curOpt == = ]]; then
102
curOpt=${COMP_WORDS[COMP_CWORD - 2]}
103
elif [[ $cur == : ]]; then
106
elif [[ $curOpt == : ]]; then
107
curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
123
if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
126
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
131
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//; s/^/tag:/') )
134
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//') )
135
fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
138
elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
139
# complete directly after "--option=", list all enum values
140
COMPREPLY=( "${optEnums[@]}" )
143
fixedWords=( "${cmdOpts[@]}"
149
if [[ ${#fixedWords[@]} -gt 0 ]]; then
150
COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
122
if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
125
fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
130
fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//; s/^/tag:/') )
133
fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//') )
134
fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
137
elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
138
# complete directly after "--option=", list all enum values
139
COMPREPLY=( "${optEnums[@]}" )
142
fixedWords=( "${cmdOpts[@]}"
148
if [[ ${#fixedWords[@]} -gt 0 ]]; then
149
COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
156
155
"cmds": self.command_names(),
157
156
"function_name": self.function_name,
158
157
"cases": self.command_cases(),
172
# Debugging code enabled using the --debug command line switch.
173
# Will dump some variables to the top portion of the terminal.
175
for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
176
echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
178
for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
179
echo "\$${i}=\"${!i}\""$'\e[K'
181
echo -ne '---\e[K\e[u'
171
# Debugging code enabled using the --debug command line switch.
172
# Will dump some variables to the top portion of the terminal.
174
for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
175
echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
177
for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
178
echo "\$${i}=\"${!i}\""$'\e[K'
180
echo -ne '---\e[K\e[u'
184
def brz_version(self):
185
brz_version = breezy.version_string
183
def bzr_version(self):
184
bzr_version = bzrlib.version_string
186
185
if not self.data.plugins:
189
brz_version += " and the following plugins:"
190
for name, plugin in sorted(self.data.plugins.items()):
191
brz_version += "\n# %s" % plugin
188
bzr_version += " and the following plugins:"
189
for name, plugin in sorted(self.data.plugins.iteritems()):
190
bzr_version += "\n# %s" % plugin
194
193
def global_options(self):
195
194
return " ".join(sorted(self.data.global_options))
347
343
# ones while maintaining the actual command name unchanged.
348
344
cmd_data.aliases.extend(cmd.aliases)
349
345
cmd_data.aliases.extend(sorted([useralias
350
for cmdalias in cmd_data.aliases
351
if cmdalias in self.user_aliases
352
for useralias in self.user_aliases[cmdalias]
353
if useralias not in cmd_data.aliases]))
346
for cmdalias in cmd_data.aliases
347
if cmdalias in self.user_aliases
348
for useralias in self.user_aliases[cmdalias]
349
if useralias not in cmd_data.aliases]))
355
351
opts = cmd.options()
356
for optname, opt in sorted(opts.items()):
352
for optname, opt in sorted(opts.iteritems()):
357
353
cmd_data.options.extend(self.option(opt))
359
355
if 'help' == name or 'help' in cmd.aliases:
360
356
cmd_data.fixed_words = ('($cmds %s)' %
361
" ".join(sorted(help_topics.topic_registry.keys())))
357
" ".join(sorted(help_topics.topic_registry.keys())))
365
361
def option(self, opt):
367
parser = option.get_optparser([opt])
363
parser = option.get_optparser({opt.name: opt})
368
364
parser = self.wrap_parser(optswitches, parser)
369
365
optswitches.clear()
370
366
opt.add_option(parser, opt.short_name())
390
386
def wrap_parser(self, optswitches, parser):
391
387
orig_add_option_group = parser.add_option_group
393
388
def tweaked_add_option_group(*opts, **attrs):
394
389
return self.wrap_container(optswitches,
395
orig_add_option_group(*opts, **attrs))
390
orig_add_option_group(*opts, **attrs))
396
391
parser.add_option_group = tweaked_add_option_group
397
392
return self.wrap_container(optswitches, parser)
400
def bash_completion_function(out, function_name="_brz", function_only=False,
395
def bash_completion_function(out, function_name="_bzr", function_only=False,
402
397
no_plugins=False, selected_plugins=None):
403
dc = DataCollector(no_plugins=no_plugins,
404
selected_plugins=selected_plugins)
398
dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
405
399
data = dc.collect()
406
400
cg = BashCodeGen(data, function_name=function_name, debug=debug)
407
401
if function_only:
417
411
This command generates a shell function which can be used by bash to
418
412
automatically complete the currently typed command when the user presses
419
413
the completion key (usually tab).
421
415
Commonly used like this:
422
eval "`brz bash-completion`"
416
eval "`bzr bash-completion`"
425
419
takes_options = [
426
420
option.Option("function-name", short_name="f", type=str, argname="name",
427
help="Name of the generated function (default: _brz)"),
421
help="Name of the generated function (default: _bzr)"),
428
422
option.Option("function-only", short_name="o", type=None,
429
help="Generate only the shell function, don't enable it"),
423
help="Generate only the shell function, don't enable it"),
430
424
option.Option("debug", type=None, hidden=True,
431
help="Enable shell code useful for debugging"),
425
help="Enable shell code useful for debugging"),
432
426
option.ListOption("plugin", type=str, argname="name",
433
# param_name="selected_plugins", # doesn't work, bug #387117
434
help="Enable completions for the selected plugin"
435
+ " (default: all plugins)"),
427
# param_name="selected_plugins", # doesn't work, bug #387117
428
help="Enable completions for the selected plugin"
429
+ " (default: all plugins)"),
438
432
def run(self, **kwargs):
434
from bashcomp import bash_completion_function
439
435
if 'plugin' in kwargs:
440
436
# work around bug #387117 which prevents us from using param_name
441
437
if len(kwargs['plugin']) > 0:
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,