71
71
%(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]}:
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]}:
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 ) )
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 ) )
161
161
"cmds": self.command_names(),
162
162
"function_name": self.function_name,
163
163
"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'
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'
189
189
def brz_version(self):
352
352
# ones while maintaining the actual command name unchanged.
353
353
cmd_data.aliases.extend(cmd.aliases)
354
354
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]))
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]))
360
360
opts = cmd.options()
361
361
for optname, opt in sorted(opts.items()):
395
395
def wrap_parser(self, optswitches, parser):
396
396
orig_add_option_group = parser.add_option_group
397
398
def tweaked_add_option_group(*opts, **attrs):
398
399
return self.wrap_container(optswitches,
399
orig_add_option_group(*opts, **attrs))
400
orig_add_option_group(*opts, **attrs))
400
401
parser.add_option_group = tweaked_add_option_group
401
402
return self.wrap_container(optswitches, parser)
420
422
This command generates a shell function which can be used by bash to
421
423
automatically complete the currently typed command when the user presses
422
424
the completion key (usually tab).
424
426
Commonly used like this:
425
427
eval "`brz bash-completion`"
428
430
takes_options = [
429
431
option.Option("function-name", short_name="f", type=text_type, argname="name",
430
help="Name of the generated function (default: _brz)"),
432
help="Name of the generated function (default: _brz)"),
431
433
option.Option("function-only", short_name="o", type=None,
432
help="Generate only the shell function, don't enable it"),
434
help="Generate only the shell function, don't enable it"),
433
435
option.Option("debug", type=None, hidden=True,
434
help="Enable shell code useful for debugging"),
436
help="Enable shell code useful for debugging"),
435
437
option.ListOption("plugin", type=text_type, argname="name",
436
# param_name="selected_plugins", # doesn't work, bug #387117
437
help="Enable completions for the selected plugin"
438
+ " (default: all plugins)"),
438
# param_name="selected_plugins", # doesn't work, bug #387117
439
help="Enable completions for the selected plugin"
440
+ " (default: all plugins)"),
441
443
def run(self, **kwargs):