66
68
%(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]}:
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]}:
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 ) )
125
if [[ ${#fixedWords[@]} -eq 0 ]] && [[ ${#optEnums[@]} -eq 0 ]] && [[ $cur != -* ]]; then
128
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//; s/ /\\\\\\\\ /g;') )
133
fixedWords=( $(brz tags 2>/dev/null | sed 's/ *[^ ]*$//; s/^/tag:/') )
136
fixedWords=( $(brz 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 ) )
156
158
"cmds": self.command_names(),
157
159
"function_name": self.function_name,
158
160
"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'
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'
184
186
def brz_version(self):
347
346
# ones while maintaining the actual command name unchanged.
348
347
cmd_data.aliases.extend(cmd.aliases)
349
348
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]))
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]))
355
354
opts = cmd.options()
356
355
for optname, opt in sorted(opts.items()):
390
389
def wrap_parser(self, optswitches, parser):
391
390
orig_add_option_group = parser.add_option_group
393
391
def tweaked_add_option_group(*opts, **attrs):
394
392
return self.wrap_container(optswitches,
395
orig_add_option_group(*opts, **attrs))
393
orig_add_option_group(*opts, **attrs))
396
394
parser.add_option_group = tweaked_add_option_group
397
395
return self.wrap_container(optswitches, parser)
417
414
This command generates a shell function which can be used by bash to
418
415
automatically complete the currently typed command when the user presses
419
416
the completion key (usually tab).
421
418
Commonly used like this:
422
419
eval "`brz bash-completion`"
425
422
takes_options = [
426
423
option.Option("function-name", short_name="f", type=str, argname="name",
427
help="Name of the generated function (default: _brz)"),
424
help="Name of the generated function (default: _brz)"),
428
425
option.Option("function-only", short_name="o", type=None,
429
help="Generate only the shell function, don't enable it"),
426
help="Generate only the shell function, don't enable it"),
430
427
option.Option("debug", type=None, hidden=True,
431
help="Enable shell code useful for debugging"),
428
help="Enable shell code useful for debugging"),
432
429
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)"),
430
# param_name="selected_plugins", # doesn't work, bug #387117
431
help="Enable completions for the selected plugin"
432
+ " (default: all plugins)"),
438
435
def run(self, **kwargs):