Revision 94014b63 autotools/build-bash-completion
b/autotools/build-bash-completion | ||
---|---|---|
520 | 520 |
@param commands: List of all subcommands in this program |
521 | 521 |
|
522 | 522 |
""" |
523 |
sw.Write("%s() {", funcname) |
|
523 |
sw.Write("%s_inner() {", funcname)
|
|
524 | 524 |
sw.IncIndent() |
525 | 525 |
try: |
526 |
sw.Write("local " |
|
526 |
sw.Write("local i first_arg_idx choices compgenargs arg_idx optcur"
|
|
527 | 527 |
' cur="${COMP_WORDS[COMP_CWORD]}"' |
528 |
' prev="${COMP_WORDS[COMP_CWORD-1]}"' |
|
529 |
' i first_arg_idx choices compgenargs arg_idx optcur') |
|
528 |
' prev="${COMP_WORDS[COMP_CWORD-1]}"') |
|
530 | 529 |
|
531 | 530 |
sw.Write("_gnt_log cur=\"$cur\" prev=\"$prev\"") |
532 | 531 |
sw.Write("[[ -n \"$GANETI_COMPL_LOG\" ]] &&" |
... | ... | |
575 | 574 |
sw.DecIndent() |
576 | 575 |
sw.Write("}") |
577 | 576 |
|
577 |
# Wrapper function to always enable extglob (needed for advanced pattern |
|
578 |
# matching) |
|
579 |
sw.Write("%s() {", funcname) |
|
580 |
sw.IncIndent() |
|
581 |
try: |
|
582 |
# Get current state of extglob |
|
583 |
sw.Write("local -r eg=$(shopt -p extglob || :)") |
|
584 |
|
|
585 |
# Enable extglob |
|
586 |
sw.Write("shopt -s extglob") |
|
587 |
|
|
588 |
sw.Write("%s_inner \"$@\"", funcname) |
|
589 |
|
|
590 |
# Reset extglob to original value |
|
591 |
sw.Write("[[ -n \"$eg\" ]] && $eg") |
|
592 |
finally: |
|
593 |
sw.DecIndent() |
|
594 |
sw.Write("}") |
|
595 |
|
|
578 | 596 |
sw.Write("complete -F %s -o filenames %s", |
579 | 597 |
utils.ShellQuote(funcname), |
580 | 598 |
utils.ShellQuote(scriptname)) |
Also available in: Unified diff