55
49
# Generated using the bash_completion plugin.
56
50
# See https://launchpad.net/bzr-bash-completion for details.
58
# Commands and options of brz %(brz_version)s
52
# Commands and options of bzr %(bzr_version)s
62
complete -F %(function_name)s -o default brz
56
complete -F %(function_name)s -o default bzr
64
58
"function_name": self.function_name,
65
59
"function": self.function(),
66
"brz_version": self.brz_version(),
60
"bzr_version": self.bzr_version(),
69
63
def function(self):
71
65
%(function_name)s ()
73
local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
78
cur=${COMP_WORDS[COMP_CWORD]}
81
globalOpts=( %(global_options)s )
83
# do ordinary expansion if we are anywhere after a -- argument
84
for ((i = 1; i < COMP_CWORD; ++i)); do
85
[[ ${COMP_WORDS[i]} == "--" ]] && return 0
88
# find the command; it's the first word not starting in -
90
for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
91
if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
92
cmd=${COMP_WORDS[cmdIdx]}
97
# complete command name if we are not already past the command
98
if [[ $COMP_CWORD -le cmdIdx ]]; then
99
COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
103
# find the option for which we want to complete a value
105
if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
106
curOpt=${COMP_WORDS[COMP_CWORD - 1]}
107
if [[ $curOpt == = ]]; then
108
curOpt=${COMP_WORDS[COMP_CWORD - 2]}
109
elif [[ $cur == : ]]; then
112
elif [[ $curOpt == : ]]; then
113
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]}:
128
if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
131
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
136
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//; s/^/tag:/') )
139
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//') )
140
fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
143
elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
144
# complete directly after "--option=", list all enum values
145
COMPREPLY=( "${optEnums[@]}" )
148
fixedWords=( "${cmdOpts[@]}"
154
if [[ ${#fixedWords[@]} -gt 0 ]]; then
155
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 ) )
161
155
"cmds": self.command_names(),
162
156
"function_name": self.function_name,
163
157
"cases": self.command_cases(),
177
# Debugging code enabled using the --debug command line switch.
178
# Will dump some variables to the top portion of the terminal.
180
for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
181
echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
183
for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
184
echo "\$${i}=\"${!i}\""$'\e[K'
186
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'
189
def brz_version(self):
190
brz_version = breezy.version_string
183
def bzr_version(self):
184
bzr_version = bzrlib.version_string
191
185
if not self.data.plugins:
194
brz_version += " and the following plugins:"
195
for name, plugin in sorted(self.data.plugins.items()):
196
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
199
193
def global_options(self):
200
194
return " ".join(sorted(self.data.global_options))
352
343
# ones while maintaining the actual command name unchanged.
353
344
cmd_data.aliases.extend(cmd.aliases)
354
345
cmd_data.aliases.extend(sorted([useralias
355
for cmdalias in cmd_data.aliases
356
if cmdalias in self.user_aliases
357
for useralias in self.user_aliases[cmdalias]
358
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]))
360
351
opts = cmd.options()
361
for optname, opt in sorted(opts.items()):
352
for optname, opt in sorted(opts.iteritems()):
362
353
cmd_data.options.extend(self.option(opt))
364
355
if 'help' == name or 'help' in cmd.aliases:
365
356
cmd_data.fixed_words = ('($cmds %s)' %
366
" ".join(sorted(help_topics.topic_registry.keys())))
357
" ".join(sorted(help_topics.topic_registry.keys())))
370
361
def option(self, opt):
372
parser = option.get_optparser([opt])
363
parser = option.get_optparser({opt.name: opt})
373
364
parser = self.wrap_parser(optswitches, parser)
374
365
optswitches.clear()
375
366
opt.add_option(parser, opt.short_name())
395
386
def wrap_parser(self, optswitches, parser):
396
387
orig_add_option_group = parser.add_option_group
398
388
def tweaked_add_option_group(*opts, **attrs):
399
389
return self.wrap_container(optswitches,
400
orig_add_option_group(*opts, **attrs))
390
orig_add_option_group(*opts, **attrs))
401
391
parser.add_option_group = tweaked_add_option_group
402
392
return self.wrap_container(optswitches, parser)
405
def bash_completion_function(out, function_name="_brz", function_only=False,
395
def bash_completion_function(out, function_name="_bzr", function_only=False,
407
397
no_plugins=False, selected_plugins=None):
408
dc = DataCollector(no_plugins=no_plugins,
409
selected_plugins=selected_plugins)
398
dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
410
399
data = dc.collect()
411
400
cg = BashCodeGen(data, function_name=function_name, debug=debug)
412
401
if function_only:
422
411
This command generates a shell function which can be used by bash to
423
412
automatically complete the currently typed command when the user presses
424
413
the completion key (usually tab).
426
415
Commonly used like this:
427
eval "`brz bash-completion`"
416
eval "`bzr bash-completion`"
430
419
takes_options = [
431
option.Option("function-name", short_name="f", type=text_type, argname="name",
432
help="Name of the generated function (default: _brz)"),
420
option.Option("function-name", short_name="f", type=str, argname="name",
421
help="Name of the generated function (default: _bzr)"),
433
422
option.Option("function-only", short_name="o", type=None,
434
help="Generate only the shell function, don't enable it"),
423
help="Generate only the shell function, don't enable it"),
435
424
option.Option("debug", type=None, hidden=True,
436
help="Enable shell code useful for debugging"),
437
option.ListOption("plugin", type=text_type, argname="name",
438
# param_name="selected_plugins", # doesn't work, bug #387117
439
help="Enable completions for the selected plugin"
440
+ " (default: all plugins)"),
425
help="Enable shell code useful for debugging"),
426
option.ListOption("plugin", type=str, argname="name",
427
# param_name="selected_plugins", # doesn't work, bug #387117
428
help="Enable completions for the selected plugin"
429
+ " (default: all plugins)"),
443
432
def run(self, **kwargs):
434
from bashcomp import bash_completion_function
444
435
if 'plugin' in kwargs:
445
436
# work around bug #387117 which prevents us from using param_name
446
437
if len(kwargs['plugin']) > 0:
464
456
parser = optparse.OptionParser(usage="%prog [-f NAME] [-o]")
465
457
parser.add_option("--function-name", "-f", metavar="NAME",
466
help="Name of the generated function (default: _brz)")
458
help="Name of the generated function (default: _bzr)")
467
459
parser.add_option("--function-only", "-o", action="store_true",
468
460
help="Generate only the shell function, don't enable it")
469
461
parser.add_option("--debug", action="store_true",
470
462
help=optparse.SUPPRESS_HELP)
471
463
parser.add_option("--no-plugins", action="store_true",
472
help="Don't load any brz plugins")
464
help="Don't load any bzr plugins")
473
465
parser.add_option("--plugin", metavar="NAME", type="string",
474
466
dest="selected_plugins", default=[],
475
467
action="callback", callback=plugin_callback,