52
50
# Generated using the bash_completion plugin.
53
51
# See https://launchpad.net/bzr-bash-completion for details.
55
# Commands and options of bzr %(bzr_version)s
53
# Commands and options of brz %(brz_version)s
59
complete -F %(function_name)s -o default bzr
57
complete -F %(function_name)s -o default brz
61
59
"function_name": self.function_name,
62
60
"function": self.function(),
63
"bzr_version": self.bzr_version(),
61
"brz_version": self.brz_version(),
66
64
def function(self):
68
66
%(function_name)s ()
70
local cur cmds cmdIdx cmd cmdOpts fixedWords i globalOpts
75
cur=${COMP_WORDS[COMP_CWORD]}
78
globalOpts=( %(global_options)s )
80
# do ordinary expansion if we are anywhere after a -- argument
81
for ((i = 1; i < COMP_CWORD; ++i)); do
82
[[ ${COMP_WORDS[i]} == "--" ]] && return 0
85
# find the command; it's the first word not starting in -
87
for ((cmdIdx = 1; cmdIdx < ${#COMP_WORDS[@]}; ++cmdIdx)); do
88
if [[ ${COMP_WORDS[cmdIdx]} != -* ]]; then
89
cmd=${COMP_WORDS[cmdIdx]}
94
# complete command name if we are not already past the command
95
if [[ $COMP_CWORD -le cmdIdx ]]; then
96
COMPREPLY=( $( compgen -W "$cmds ${globalOpts[*]}" -- $cur ) )
100
# find the option for which we want to complete a value
102
if [[ $cur != -* ]] && [[ $COMP_CWORD -gt 1 ]]; then
103
curOpt=${COMP_WORDS[COMP_CWORD - 1]}
104
if [[ $curOpt == = ]]; then
105
curOpt=${COMP_WORDS[COMP_CWORD - 2]}
106
elif [[ $cur == : ]]; then
109
elif [[ $curOpt == : ]]; then
110
curOpt=${COMP_WORDS[COMP_CWORD - 2]}:
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]}:
125
if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
128
fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
133
fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//; s/^/tag:/') )
136
fixedWords=( $(bzr tags 2>/dev/null | sed 's/ *[^ ]*$//') )
137
fixedWords=( $(for i in "${fixedWords[@]}"; do echo "${cur%%..tag:*}..tag:${i}"; done) )
140
elif [[ $cur == = ]] && [[ ${#optEnums[@]} -gt 0 ]]; then
141
# complete directly after "--option=", list all enum values
142
COMPREPLY=( "${optEnums[@]}" )
145
fixedWords=( "${cmdOpts[@]}"
151
if [[ ${#fixedWords[@]} -gt 0 ]]; then
152
COMPREPLY=( $( compgen -W "${fixedWords[*]}" -- $cur ) )
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 ) )
158
156
"cmds": self.command_names(),
159
157
"function_name": self.function_name,
160
158
"cases": self.command_cases(),
174
# Debugging code enabled using the --debug command line switch.
175
# Will dump some variables to the top portion of the terminal.
177
for (( i=0; i < ${#COMP_WORDS[@]}; ++i)); do
178
echo "\$COMP_WORDS[$i]='${COMP_WORDS[i]}'"$'\e[K'
180
for i in COMP_CWORD COMP_LINE COMP_POINT COMP_TYPE COMP_KEY cur curOpt; do
181
echo "\$${i}=\"${!i}\""$'\e[K'
183
echo -ne '---\e[K\e[u'
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'
186
def bzr_version(self):
187
bzr_version = bzrlib.version_string
184
def brz_version(self):
185
brz_version = breezy.version_string
188
186
if not self.data.plugins:
191
bzr_version += " and the following plugins:"
192
for name, plugin in sorted(self.data.plugins.iteritems()):
193
bzr_version += "\n# %s" % plugin
189
brz_version += " and the following plugins:"
190
for name, plugin in sorted(self.data.plugins.items()):
191
brz_version += "\n# %s" % plugin
196
194
def global_options(self):
197
195
return " ".join(sorted(self.data.global_options))
346
347
# ones while maintaining the actual command name unchanged.
347
348
cmd_data.aliases.extend(cmd.aliases)
348
349
cmd_data.aliases.extend(sorted([useralias
349
for cmdalias in cmd_data.aliases
350
if cmdalias in self.user_aliases
351
for useralias in self.user_aliases[cmdalias]
352
if useralias not in cmd_data.aliases]))
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]))
354
355
opts = cmd.options()
355
for optname, opt in sorted(opts.iteritems()):
356
for optname, opt in sorted(opts.items()):
356
357
cmd_data.options.extend(self.option(opt))
358
359
if 'help' == name or 'help' in cmd.aliases:
359
360
cmd_data.fixed_words = ('($cmds %s)' %
360
" ".join(sorted(help_topics.topic_registry.keys())))
361
" ".join(sorted(help_topics.topic_registry.keys())))
364
365
def option(self, opt):
366
parser = option.get_optparser({opt.name: opt})
367
parser = option.get_optparser([opt])
367
368
parser = self.wrap_parser(optswitches, parser)
368
369
optswitches.clear()
369
370
opt.add_option(parser, opt.short_name())
389
390
def wrap_parser(self, optswitches, parser):
390
391
orig_add_option_group = parser.add_option_group
391
393
def tweaked_add_option_group(*opts, **attrs):
392
394
return self.wrap_container(optswitches,
393
orig_add_option_group(*opts, **attrs))
395
orig_add_option_group(*opts, **attrs))
394
396
parser.add_option_group = tweaked_add_option_group
395
397
return self.wrap_container(optswitches, parser)
398
def bash_completion_function(out, function_name="_bzr", function_only=False,
400
def bash_completion_function(out, function_name="_brz", function_only=False,
400
402
no_plugins=False, selected_plugins=None):
401
dc = DataCollector(no_plugins=no_plugins, selected_plugins=selected_plugins)
403
dc = DataCollector(no_plugins=no_plugins,
404
selected_plugins=selected_plugins)
402
405
data = dc.collect()
403
406
cg = BashCodeGen(data, function_name=function_name, debug=debug)
404
407
if function_only:
414
417
This command generates a shell function which can be used by bash to
415
418
automatically complete the currently typed command when the user presses
416
419
the completion key (usually tab).
418
421
Commonly used like this:
419
eval "`bzr bash-completion`"
422
eval "`brz bash-completion`"
422
425
takes_options = [
423
426
option.Option("function-name", short_name="f", type=str, argname="name",
424
help="Name of the generated function (default: _bzr)"),
427
help="Name of the generated function (default: _brz)"),
425
428
option.Option("function-only", short_name="o", type=None,
426
help="Generate only the shell function, don't enable it"),
429
help="Generate only the shell function, don't enable it"),
427
430
option.Option("debug", type=None, hidden=True,
428
help="Enable shell code useful for debugging"),
431
help="Enable shell code useful for debugging"),
429
432
option.ListOption("plugin", type=str, argname="name",
430
# param_name="selected_plugins", # doesn't work, bug #387117
431
help="Enable completions for the selected plugin"
432
+ " (default: all plugins)"),
433
# param_name="selected_plugins", # doesn't work, bug #387117
434
help="Enable completions for the selected plugin"
435
+ " (default: all plugins)"),
435
438
def run(self, **kwargs):
456
459
parser = optparse.OptionParser(usage="%prog [-f NAME] [-o]")
457
460
parser.add_option("--function-name", "-f", metavar="NAME",
458
help="Name of the generated function (default: _bzr)")
461
help="Name of the generated function (default: _brz)")
459
462
parser.add_option("--function-only", "-o", action="store_true",
460
463
help="Generate only the shell function, don't enable it")
461
464
parser.add_option("--debug", action="store_true",
462
465
help=optparse.SUPPRESS_HELP)
463
466
parser.add_option("--no-plugins", action="store_true",
464
help="Don't load any bzr plugins")
467
help="Don't load any brz plugins")
465
468
parser.add_option("--plugin", metavar="NAME", type="string",
466
469
dest="selected_plugins", default=[],
467
470
action="callback", callback=plugin_callback,