git-bug

   1# bash completion for git-bug                              -*- shell-script -*-
   2
   3__git-bug_debug()
   4{
   5    if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
   6        echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
   7    fi
   8}
   9
  10# Homebrew on Macs have version 1.3 of bash-completion which doesn't include
  11# _init_completion. This is a very minimal version of that function.
  12__git-bug_init_completion()
  13{
  14    COMPREPLY=()
  15    _get_comp_words_by_ref "$@" cur prev words cword
  16}
  17
  18__git-bug_index_of_word()
  19{
  20    local w word=$1
  21    shift
  22    index=0
  23    for w in "$@"; do
  24        [[ $w = "$word" ]] && return
  25        index=$((index+1))
  26    done
  27    index=-1
  28}
  29
  30__git-bug_contains_word()
  31{
  32    local w word=$1; shift
  33    for w in "$@"; do
  34        [[ $w = "$word" ]] && return
  35    done
  36    return 1
  37}
  38
  39__git-bug_handle_go_custom_completion()
  40{
  41    __git-bug_debug "${FUNCNAME[0]}: cur is ${cur}, words[*] is ${words[*]}, #words[@] is ${#words[@]}"
  42
  43    local shellCompDirectiveError=1
  44    local shellCompDirectiveNoSpace=2
  45    local shellCompDirectiveNoFileComp=4
  46    local shellCompDirectiveFilterFileExt=8
  47    local shellCompDirectiveFilterDirs=16
  48
  49    local out requestComp lastParam lastChar comp directive args
  50
  51    # Prepare the command to request completions for the program.
  52    # Calling ${words[0]} instead of directly git-bug allows to handle aliases
  53    args=("${words[@]:1}")
  54    requestComp="${words[0]} __completeNoDesc ${args[*]}"
  55
  56    lastParam=${words[$((${#words[@]}-1))]}
  57    lastChar=${lastParam:$((${#lastParam}-1)):1}
  58    __git-bug_debug "${FUNCNAME[0]}: lastParam ${lastParam}, lastChar ${lastChar}"
  59
  60    if [ -z "${cur}" ] && [ "${lastChar}" != "=" ]; then
  61        # If the last parameter is complete (there is a space following it)
  62        # We add an extra empty parameter so we can indicate this to the go method.
  63        __git-bug_debug "${FUNCNAME[0]}: Adding extra empty parameter"
  64        requestComp="${requestComp} \"\""
  65    fi
  66
  67    __git-bug_debug "${FUNCNAME[0]}: calling ${requestComp}"
  68    # Use eval to handle any environment variables and such
  69    out=$(eval "${requestComp}" 2>/dev/null)
  70
  71    # Extract the directive integer at the very end of the output following a colon (:)
  72    directive=${out##*:}
  73    # Remove the directive
  74    out=${out%:*}
  75    if [ "${directive}" = "${out}" ]; then
  76        # There is not directive specified
  77        directive=0
  78    fi
  79    __git-bug_debug "${FUNCNAME[0]}: the completion directive is: ${directive}"
  80    __git-bug_debug "${FUNCNAME[0]}: the completions are: ${out[*]}"
  81
  82    if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
  83        # Error code.  No completion.
  84        __git-bug_debug "${FUNCNAME[0]}: received error from custom completion go code"
  85        return
  86    else
  87        if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
  88            if [[ $(type -t compopt) = "builtin" ]]; then
  89                __git-bug_debug "${FUNCNAME[0]}: activating no space"
  90                compopt -o nospace
  91            fi
  92        fi
  93        if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
  94            if [[ $(type -t compopt) = "builtin" ]]; then
  95                __git-bug_debug "${FUNCNAME[0]}: activating no file completion"
  96                compopt +o default
  97            fi
  98        fi
  99    fi
 100
 101    if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
 102        # File extension filtering
 103        local fullFilter filter filteringCmd
 104        # Do not use quotes around the $out variable or else newline
 105        # characters will be kept.
 106        for filter in ${out[*]}; do
 107            fullFilter+="$filter|"
 108        done
 109
 110        filteringCmd="_filedir $fullFilter"
 111        __git-bug_debug "File filtering command: $filteringCmd"
 112        $filteringCmd
 113    elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
 114        # File completion for directories only
 115        local subDir
 116        # Use printf to strip any trailing newline
 117        subdir=$(printf "%s" "${out[0]}")
 118        if [ -n "$subdir" ]; then
 119            __git-bug_debug "Listing directories in $subdir"
 120            __git-bug_handle_subdirs_in_dir_flag "$subdir"
 121        else
 122            __git-bug_debug "Listing directories in ."
 123            _filedir -d
 124        fi
 125    else
 126        while IFS='' read -r comp; do
 127            COMPREPLY+=("$comp")
 128        done < <(compgen -W "${out[*]}" -- "$cur")
 129    fi
 130}
 131
 132__git-bug_handle_reply()
 133{
 134    __git-bug_debug "${FUNCNAME[0]}"
 135    local comp
 136    case $cur in
 137        -*)
 138            if [[ $(type -t compopt) = "builtin" ]]; then
 139                compopt -o nospace
 140            fi
 141            local allflags
 142            if [ ${#must_have_one_flag[@]} -ne 0 ]; then
 143                allflags=("${must_have_one_flag[@]}")
 144            else
 145                allflags=("${flags[*]} ${two_word_flags[*]}")
 146            fi
 147            while IFS='' read -r comp; do
 148                COMPREPLY+=("$comp")
 149            done < <(compgen -W "${allflags[*]}" -- "$cur")
 150            if [[ $(type -t compopt) = "builtin" ]]; then
 151                [[ "${COMPREPLY[0]}" == *= ]] || compopt +o nospace
 152            fi
 153
 154            # complete after --flag=abc
 155            if [[ $cur == *=* ]]; then
 156                if [[ $(type -t compopt) = "builtin" ]]; then
 157                    compopt +o nospace
 158                fi
 159
 160                local index flag
 161                flag="${cur%=*}"
 162                __git-bug_index_of_word "${flag}" "${flags_with_completion[@]}"
 163                COMPREPLY=()
 164                if [[ ${index} -ge 0 ]]; then
 165                    PREFIX=""
 166                    cur="${cur#*=}"
 167                    ${flags_completion[${index}]}
 168                    if [ -n "${ZSH_VERSION}" ]; then
 169                        # zsh completion needs --flag= prefix
 170                        eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
 171                    fi
 172                fi
 173            fi
 174            return 0;
 175            ;;
 176    esac
 177
 178    # check if we are handling a flag with special work handling
 179    local index
 180    __git-bug_index_of_word "${prev}" "${flags_with_completion[@]}"
 181    if [[ ${index} -ge 0 ]]; then
 182        ${flags_completion[${index}]}
 183        return
 184    fi
 185
 186    # we are parsing a flag and don't have a special handler, no completion
 187    if [[ ${cur} != "${words[cword]}" ]]; then
 188        return
 189    fi
 190
 191    local completions
 192    completions=("${commands[@]}")
 193    if [[ ${#must_have_one_noun[@]} -ne 0 ]]; then
 194        completions+=("${must_have_one_noun[@]}")
 195    elif [[ -n "${has_completion_function}" ]]; then
 196        # if a go completion function is provided, defer to that function
 197        __git-bug_handle_go_custom_completion
 198    fi
 199    if [[ ${#must_have_one_flag[@]} -ne 0 ]]; then
 200        completions+=("${must_have_one_flag[@]}")
 201    fi
 202    while IFS='' read -r comp; do
 203        COMPREPLY+=("$comp")
 204    done < <(compgen -W "${completions[*]}" -- "$cur")
 205
 206    if [[ ${#COMPREPLY[@]} -eq 0 && ${#noun_aliases[@]} -gt 0 && ${#must_have_one_noun[@]} -ne 0 ]]; then
 207        while IFS='' read -r comp; do
 208            COMPREPLY+=("$comp")
 209        done < <(compgen -W "${noun_aliases[*]}" -- "$cur")
 210    fi
 211
 212    if [[ ${#COMPREPLY[@]} -eq 0 ]]; then
 213		if declare -F __git-bug_custom_func >/dev/null; then
 214			# try command name qualified custom func
 215			__git-bug_custom_func
 216		else
 217			# otherwise fall back to unqualified for compatibility
 218			declare -F __custom_func >/dev/null && __custom_func
 219		fi
 220    fi
 221
 222    # available in bash-completion >= 2, not always present on macOS
 223    if declare -F __ltrim_colon_completions >/dev/null; then
 224        __ltrim_colon_completions "$cur"
 225    fi
 226
 227    # If there is only 1 completion and it is a flag with an = it will be completed
 228    # but we don't want a space after the =
 229    if [[ "${#COMPREPLY[@]}" -eq "1" ]] && [[ $(type -t compopt) = "builtin" ]] && [[ "${COMPREPLY[0]}" == --*= ]]; then
 230       compopt -o nospace
 231    fi
 232}
 233
 234# The arguments should be in the form "ext1|ext2|extn"
 235__git-bug_handle_filename_extension_flag()
 236{
 237    local ext="$1"
 238    _filedir "@(${ext})"
 239}
 240
 241__git-bug_handle_subdirs_in_dir_flag()
 242{
 243    local dir="$1"
 244    pushd "${dir}" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return
 245}
 246
 247__git-bug_handle_flag()
 248{
 249    __git-bug_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
 250
 251    # if a command required a flag, and we found it, unset must_have_one_flag()
 252    local flagname=${words[c]}
 253    local flagvalue
 254    # if the word contained an =
 255    if [[ ${words[c]} == *"="* ]]; then
 256        flagvalue=${flagname#*=} # take in as flagvalue after the =
 257        flagname=${flagname%=*} # strip everything after the =
 258        flagname="${flagname}=" # but put the = back
 259    fi
 260    __git-bug_debug "${FUNCNAME[0]}: looking for ${flagname}"
 261    if __git-bug_contains_word "${flagname}" "${must_have_one_flag[@]}"; then
 262        must_have_one_flag=()
 263    fi
 264
 265    # if you set a flag which only applies to this command, don't show subcommands
 266    if __git-bug_contains_word "${flagname}" "${local_nonpersistent_flags[@]}"; then
 267      commands=()
 268    fi
 269
 270    # keep flag value with flagname as flaghash
 271    # flaghash variable is an associative array which is only supported in bash > 3.
 272    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
 273        if [ -n "${flagvalue}" ] ; then
 274            flaghash[${flagname}]=${flagvalue}
 275        elif [ -n "${words[ $((c+1)) ]}" ] ; then
 276            flaghash[${flagname}]=${words[ $((c+1)) ]}
 277        else
 278            flaghash[${flagname}]="true" # pad "true" for bool flag
 279        fi
 280    fi
 281
 282    # skip the argument to a two word flag
 283    if [[ ${words[c]} != *"="* ]] && __git-bug_contains_word "${words[c]}" "${two_word_flags[@]}"; then
 284			  __git-bug_debug "${FUNCNAME[0]}: found a flag ${words[c]}, skip the next argument"
 285        c=$((c+1))
 286        # if we are looking for a flags value, don't show commands
 287        if [[ $c -eq $cword ]]; then
 288            commands=()
 289        fi
 290    fi
 291
 292    c=$((c+1))
 293
 294}
 295
 296__git-bug_handle_noun()
 297{
 298    __git-bug_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
 299
 300    if __git-bug_contains_word "${words[c]}" "${must_have_one_noun[@]}"; then
 301        must_have_one_noun=()
 302    elif __git-bug_contains_word "${words[c]}" "${noun_aliases[@]}"; then
 303        must_have_one_noun=()
 304    fi
 305
 306    nouns+=("${words[c]}")
 307    c=$((c+1))
 308}
 309
 310__git-bug_handle_command()
 311{
 312    __git-bug_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
 313
 314    local next_command
 315    if [[ -n ${last_command} ]]; then
 316        next_command="_${last_command}_${words[c]//:/__}"
 317    else
 318        if [[ $c -eq 0 ]]; then
 319            next_command="_git-bug_root_command"
 320        else
 321            next_command="_${words[c]//:/__}"
 322        fi
 323    fi
 324    c=$((c+1))
 325    __git-bug_debug "${FUNCNAME[0]}: looking for ${next_command}"
 326    declare -F "$next_command" >/dev/null && $next_command
 327}
 328
 329__git-bug_handle_word()
 330{
 331    if [[ $c -ge $cword ]]; then
 332        __git-bug_handle_reply
 333        return
 334    fi
 335    __git-bug_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}"
 336    if [[ "${words[c]}" == -* ]]; then
 337        __git-bug_handle_flag
 338    elif __git-bug_contains_word "${words[c]}" "${commands[@]}"; then
 339        __git-bug_handle_command
 340    elif [[ $c -eq 0 ]]; then
 341        __git-bug_handle_command
 342    elif __git-bug_contains_word "${words[c]}" "${command_aliases[@]}"; then
 343        # aliashash variable is an associative array which is only supported in bash > 3.
 344        if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
 345            words[c]=${aliashash[${words[c]}]}
 346            __git-bug_handle_command
 347        else
 348            __git-bug_handle_noun
 349        fi
 350    else
 351        __git-bug_handle_noun
 352    fi
 353    __git-bug_handle_word
 354}
 355
 356
 357_git_bug() {
 358    __start_git-bug "$@"
 359}
 360
 361_git-bug_add()
 362{
 363    last_command="git-bug_add"
 364
 365    command_aliases=()
 366
 367    commands=()
 368
 369    flags=()
 370    two_word_flags=()
 371    local_nonpersistent_flags=()
 372    flags_with_completion=()
 373    flags_completion=()
 374
 375    flags+=("--title=")
 376    two_word_flags+=("--title")
 377    two_word_flags+=("-t")
 378    local_nonpersistent_flags+=("--title")
 379    local_nonpersistent_flags+=("--title=")
 380    local_nonpersistent_flags+=("-t")
 381    flags+=("--message=")
 382    two_word_flags+=("--message")
 383    two_word_flags+=("-m")
 384    local_nonpersistent_flags+=("--message")
 385    local_nonpersistent_flags+=("--message=")
 386    local_nonpersistent_flags+=("-m")
 387    flags+=("--file=")
 388    two_word_flags+=("--file")
 389    two_word_flags+=("-F")
 390    local_nonpersistent_flags+=("--file")
 391    local_nonpersistent_flags+=("--file=")
 392    local_nonpersistent_flags+=("-F")
 393    flags+=("--non-interactive")
 394    local_nonpersistent_flags+=("--non-interactive")
 395
 396    must_have_one_flag=()
 397    must_have_one_noun=()
 398    noun_aliases=()
 399}
 400
 401_git-bug_bridge_auth_add-token()
 402{
 403    last_command="git-bug_bridge_auth_add-token"
 404
 405    command_aliases=()
 406
 407    commands=()
 408
 409    flags=()
 410    two_word_flags=()
 411    local_nonpersistent_flags=()
 412    flags_with_completion=()
 413    flags_completion=()
 414
 415    flags+=("--target=")
 416    two_word_flags+=("--target")
 417    two_word_flags+=("-t")
 418    local_nonpersistent_flags+=("--target")
 419    local_nonpersistent_flags+=("--target=")
 420    local_nonpersistent_flags+=("-t")
 421    flags+=("--login=")
 422    two_word_flags+=("--login")
 423    two_word_flags+=("-l")
 424    local_nonpersistent_flags+=("--login")
 425    local_nonpersistent_flags+=("--login=")
 426    local_nonpersistent_flags+=("-l")
 427    flags+=("--user=")
 428    two_word_flags+=("--user")
 429    two_word_flags+=("-u")
 430    local_nonpersistent_flags+=("--user")
 431    local_nonpersistent_flags+=("--user=")
 432    local_nonpersistent_flags+=("-u")
 433
 434    must_have_one_flag=()
 435    must_have_one_noun=()
 436    noun_aliases=()
 437}
 438
 439_git-bug_bridge_auth_rm()
 440{
 441    last_command="git-bug_bridge_auth_rm"
 442
 443    command_aliases=()
 444
 445    commands=()
 446
 447    flags=()
 448    two_word_flags=()
 449    local_nonpersistent_flags=()
 450    flags_with_completion=()
 451    flags_completion=()
 452
 453
 454    must_have_one_flag=()
 455    must_have_one_noun=()
 456    noun_aliases=()
 457}
 458
 459_git-bug_bridge_auth_show()
 460{
 461    last_command="git-bug_bridge_auth_show"
 462
 463    command_aliases=()
 464
 465    commands=()
 466
 467    flags=()
 468    two_word_flags=()
 469    local_nonpersistent_flags=()
 470    flags_with_completion=()
 471    flags_completion=()
 472
 473
 474    must_have_one_flag=()
 475    must_have_one_noun=()
 476    noun_aliases=()
 477}
 478
 479_git-bug_bridge_auth()
 480{
 481    last_command="git-bug_bridge_auth"
 482
 483    command_aliases=()
 484
 485    commands=()
 486    commands+=("add-token")
 487    commands+=("rm")
 488    commands+=("show")
 489
 490    flags=()
 491    two_word_flags=()
 492    local_nonpersistent_flags=()
 493    flags_with_completion=()
 494    flags_completion=()
 495
 496
 497    must_have_one_flag=()
 498    must_have_one_noun=()
 499    noun_aliases=()
 500}
 501
 502_git-bug_bridge_configure()
 503{
 504    last_command="git-bug_bridge_configure"
 505
 506    command_aliases=()
 507
 508    commands=()
 509
 510    flags=()
 511    two_word_flags=()
 512    local_nonpersistent_flags=()
 513    flags_with_completion=()
 514    flags_completion=()
 515
 516    flags+=("--name=")
 517    two_word_flags+=("--name")
 518    two_word_flags+=("-n")
 519    local_nonpersistent_flags+=("--name")
 520    local_nonpersistent_flags+=("--name=")
 521    local_nonpersistent_flags+=("-n")
 522    flags+=("--target=")
 523    two_word_flags+=("--target")
 524    two_word_flags+=("-t")
 525    local_nonpersistent_flags+=("--target")
 526    local_nonpersistent_flags+=("--target=")
 527    local_nonpersistent_flags+=("-t")
 528    flags+=("--url=")
 529    two_word_flags+=("--url")
 530    two_word_flags+=("-u")
 531    local_nonpersistent_flags+=("--url")
 532    local_nonpersistent_flags+=("--url=")
 533    local_nonpersistent_flags+=("-u")
 534    flags+=("--base-url=")
 535    two_word_flags+=("--base-url")
 536    two_word_flags+=("-b")
 537    local_nonpersistent_flags+=("--base-url")
 538    local_nonpersistent_flags+=("--base-url=")
 539    local_nonpersistent_flags+=("-b")
 540    flags+=("--login=")
 541    two_word_flags+=("--login")
 542    two_word_flags+=("-l")
 543    local_nonpersistent_flags+=("--login")
 544    local_nonpersistent_flags+=("--login=")
 545    local_nonpersistent_flags+=("-l")
 546    flags+=("--credential=")
 547    two_word_flags+=("--credential")
 548    two_word_flags+=("-c")
 549    local_nonpersistent_flags+=("--credential")
 550    local_nonpersistent_flags+=("--credential=")
 551    local_nonpersistent_flags+=("-c")
 552    flags+=("--token=")
 553    two_word_flags+=("--token")
 554    local_nonpersistent_flags+=("--token")
 555    local_nonpersistent_flags+=("--token=")
 556    flags+=("--token-stdin")
 557    local_nonpersistent_flags+=("--token-stdin")
 558    flags+=("--owner=")
 559    two_word_flags+=("--owner")
 560    two_word_flags+=("-o")
 561    local_nonpersistent_flags+=("--owner")
 562    local_nonpersistent_flags+=("--owner=")
 563    local_nonpersistent_flags+=("-o")
 564    flags+=("--project=")
 565    two_word_flags+=("--project")
 566    two_word_flags+=("-p")
 567    local_nonpersistent_flags+=("--project")
 568    local_nonpersistent_flags+=("--project=")
 569    local_nonpersistent_flags+=("-p")
 570    flags+=("--non-interactive")
 571    local_nonpersistent_flags+=("--non-interactive")
 572
 573    must_have_one_flag=()
 574    must_have_one_noun=()
 575    noun_aliases=()
 576}
 577
 578_git-bug_bridge_pull()
 579{
 580    last_command="git-bug_bridge_pull"
 581
 582    command_aliases=()
 583
 584    commands=()
 585
 586    flags=()
 587    two_word_flags=()
 588    local_nonpersistent_flags=()
 589    flags_with_completion=()
 590    flags_completion=()
 591
 592    flags+=("--no-resume")
 593    flags+=("-n")
 594    local_nonpersistent_flags+=("--no-resume")
 595    local_nonpersistent_flags+=("-n")
 596    flags+=("--since=")
 597    two_word_flags+=("--since")
 598    two_word_flags+=("-s")
 599    local_nonpersistent_flags+=("--since")
 600    local_nonpersistent_flags+=("--since=")
 601    local_nonpersistent_flags+=("-s")
 602
 603    must_have_one_flag=()
 604    must_have_one_noun=()
 605    noun_aliases=()
 606}
 607
 608_git-bug_bridge_push()
 609{
 610    last_command="git-bug_bridge_push"
 611
 612    command_aliases=()
 613
 614    commands=()
 615
 616    flags=()
 617    two_word_flags=()
 618    local_nonpersistent_flags=()
 619    flags_with_completion=()
 620    flags_completion=()
 621
 622
 623    must_have_one_flag=()
 624    must_have_one_noun=()
 625    noun_aliases=()
 626}
 627
 628_git-bug_bridge_rm()
 629{
 630    last_command="git-bug_bridge_rm"
 631
 632    command_aliases=()
 633
 634    commands=()
 635
 636    flags=()
 637    two_word_flags=()
 638    local_nonpersistent_flags=()
 639    flags_with_completion=()
 640    flags_completion=()
 641
 642
 643    must_have_one_flag=()
 644    must_have_one_noun=()
 645    noun_aliases=()
 646}
 647
 648_git-bug_bridge()
 649{
 650    last_command="git-bug_bridge"
 651
 652    command_aliases=()
 653
 654    commands=()
 655    commands+=("auth")
 656    commands+=("configure")
 657    commands+=("pull")
 658    commands+=("push")
 659    commands+=("rm")
 660
 661    flags=()
 662    two_word_flags=()
 663    local_nonpersistent_flags=()
 664    flags_with_completion=()
 665    flags_completion=()
 666
 667
 668    must_have_one_flag=()
 669    must_have_one_noun=()
 670    noun_aliases=()
 671}
 672
 673_git-bug_commands()
 674{
 675    last_command="git-bug_commands"
 676
 677    command_aliases=()
 678
 679    commands=()
 680
 681    flags=()
 682    two_word_flags=()
 683    local_nonpersistent_flags=()
 684    flags_with_completion=()
 685    flags_completion=()
 686
 687    flags+=("--pretty")
 688    flags+=("-p")
 689    local_nonpersistent_flags+=("--pretty")
 690    local_nonpersistent_flags+=("-p")
 691
 692    must_have_one_flag=()
 693    must_have_one_noun=()
 694    noun_aliases=()
 695}
 696
 697_git-bug_comment_add()
 698{
 699    last_command="git-bug_comment_add"
 700
 701    command_aliases=()
 702
 703    commands=()
 704
 705    flags=()
 706    two_word_flags=()
 707    local_nonpersistent_flags=()
 708    flags_with_completion=()
 709    flags_completion=()
 710
 711    flags+=("--file=")
 712    two_word_flags+=("--file")
 713    two_word_flags+=("-F")
 714    local_nonpersistent_flags+=("--file")
 715    local_nonpersistent_flags+=("--file=")
 716    local_nonpersistent_flags+=("-F")
 717    flags+=("--message=")
 718    two_word_flags+=("--message")
 719    two_word_flags+=("-m")
 720    local_nonpersistent_flags+=("--message")
 721    local_nonpersistent_flags+=("--message=")
 722    local_nonpersistent_flags+=("-m")
 723    flags+=("--non-interactive")
 724    local_nonpersistent_flags+=("--non-interactive")
 725
 726    must_have_one_flag=()
 727    must_have_one_noun=()
 728    noun_aliases=()
 729}
 730
 731_git-bug_comment_edit()
 732{
 733    last_command="git-bug_comment_edit"
 734
 735    command_aliases=()
 736
 737    commands=()
 738
 739    flags=()
 740    two_word_flags=()
 741    local_nonpersistent_flags=()
 742    flags_with_completion=()
 743    flags_completion=()
 744
 745    flags+=("--file=")
 746    two_word_flags+=("--file")
 747    two_word_flags+=("-F")
 748    local_nonpersistent_flags+=("--file")
 749    local_nonpersistent_flags+=("--file=")
 750    local_nonpersistent_flags+=("-F")
 751    flags+=("--message=")
 752    two_word_flags+=("--message")
 753    two_word_flags+=("-m")
 754    local_nonpersistent_flags+=("--message")
 755    local_nonpersistent_flags+=("--message=")
 756    local_nonpersistent_flags+=("-m")
 757    flags+=("--non-interactive")
 758    local_nonpersistent_flags+=("--non-interactive")
 759
 760    must_have_one_flag=()
 761    must_have_one_noun=()
 762    noun_aliases=()
 763}
 764
 765_git-bug_comment()
 766{
 767    last_command="git-bug_comment"
 768
 769    command_aliases=()
 770
 771    commands=()
 772    commands+=("add")
 773    commands+=("edit")
 774
 775    flags=()
 776    two_word_flags=()
 777    local_nonpersistent_flags=()
 778    flags_with_completion=()
 779    flags_completion=()
 780
 781
 782    must_have_one_flag=()
 783    must_have_one_noun=()
 784    noun_aliases=()
 785}
 786
 787_git-bug_deselect()
 788{
 789    last_command="git-bug_deselect"
 790
 791    command_aliases=()
 792
 793    commands=()
 794
 795    flags=()
 796    two_word_flags=()
 797    local_nonpersistent_flags=()
 798    flags_with_completion=()
 799    flags_completion=()
 800
 801
 802    must_have_one_flag=()
 803    must_have_one_noun=()
 804    noun_aliases=()
 805}
 806
 807_git-bug_label_add()
 808{
 809    last_command="git-bug_label_add"
 810
 811    command_aliases=()
 812
 813    commands=()
 814
 815    flags=()
 816    two_word_flags=()
 817    local_nonpersistent_flags=()
 818    flags_with_completion=()
 819    flags_completion=()
 820
 821
 822    must_have_one_flag=()
 823    must_have_one_noun=()
 824    noun_aliases=()
 825}
 826
 827_git-bug_label_rm()
 828{
 829    last_command="git-bug_label_rm"
 830
 831    command_aliases=()
 832
 833    commands=()
 834
 835    flags=()
 836    two_word_flags=()
 837    local_nonpersistent_flags=()
 838    flags_with_completion=()
 839    flags_completion=()
 840
 841
 842    must_have_one_flag=()
 843    must_have_one_noun=()
 844    noun_aliases=()
 845}
 846
 847_git-bug_label()
 848{
 849    last_command="git-bug_label"
 850
 851    command_aliases=()
 852
 853    commands=()
 854    commands+=("add")
 855    commands+=("rm")
 856
 857    flags=()
 858    two_word_flags=()
 859    local_nonpersistent_flags=()
 860    flags_with_completion=()
 861    flags_completion=()
 862
 863
 864    must_have_one_flag=()
 865    must_have_one_noun=()
 866    noun_aliases=()
 867}
 868
 869_git-bug_ls()
 870{
 871    last_command="git-bug_ls"
 872
 873    command_aliases=()
 874
 875    commands=()
 876
 877    flags=()
 878    two_word_flags=()
 879    local_nonpersistent_flags=()
 880    flags_with_completion=()
 881    flags_completion=()
 882
 883    flags+=("--status=")
 884    two_word_flags+=("--status")
 885    two_word_flags+=("-s")
 886    local_nonpersistent_flags+=("--status")
 887    local_nonpersistent_flags+=("--status=")
 888    local_nonpersistent_flags+=("-s")
 889    flags+=("--author=")
 890    two_word_flags+=("--author")
 891    two_word_flags+=("-a")
 892    local_nonpersistent_flags+=("--author")
 893    local_nonpersistent_flags+=("--author=")
 894    local_nonpersistent_flags+=("-a")
 895    flags+=("--metadata=")
 896    two_word_flags+=("--metadata")
 897    two_word_flags+=("-m")
 898    local_nonpersistent_flags+=("--metadata")
 899    local_nonpersistent_flags+=("--metadata=")
 900    local_nonpersistent_flags+=("-m")
 901    flags+=("--participant=")
 902    two_word_flags+=("--participant")
 903    two_word_flags+=("-p")
 904    local_nonpersistent_flags+=("--participant")
 905    local_nonpersistent_flags+=("--participant=")
 906    local_nonpersistent_flags+=("-p")
 907    flags+=("--actor=")
 908    two_word_flags+=("--actor")
 909    two_word_flags+=("-A")
 910    local_nonpersistent_flags+=("--actor")
 911    local_nonpersistent_flags+=("--actor=")
 912    local_nonpersistent_flags+=("-A")
 913    flags+=("--label=")
 914    two_word_flags+=("--label")
 915    two_word_flags+=("-l")
 916    local_nonpersistent_flags+=("--label")
 917    local_nonpersistent_flags+=("--label=")
 918    local_nonpersistent_flags+=("-l")
 919    flags+=("--title=")
 920    two_word_flags+=("--title")
 921    two_word_flags+=("-t")
 922    local_nonpersistent_flags+=("--title")
 923    local_nonpersistent_flags+=("--title=")
 924    local_nonpersistent_flags+=("-t")
 925    flags+=("--no=")
 926    two_word_flags+=("--no")
 927    two_word_flags+=("-n")
 928    local_nonpersistent_flags+=("--no")
 929    local_nonpersistent_flags+=("--no=")
 930    local_nonpersistent_flags+=("-n")
 931    flags+=("--by=")
 932    two_word_flags+=("--by")
 933    two_word_flags+=("-b")
 934    local_nonpersistent_flags+=("--by")
 935    local_nonpersistent_flags+=("--by=")
 936    local_nonpersistent_flags+=("-b")
 937    flags+=("--direction=")
 938    two_word_flags+=("--direction")
 939    two_word_flags+=("-d")
 940    local_nonpersistent_flags+=("--direction")
 941    local_nonpersistent_flags+=("--direction=")
 942    local_nonpersistent_flags+=("-d")
 943    flags+=("--format=")
 944    two_word_flags+=("--format")
 945    two_word_flags+=("-f")
 946    local_nonpersistent_flags+=("--format")
 947    local_nonpersistent_flags+=("--format=")
 948    local_nonpersistent_flags+=("-f")
 949
 950    must_have_one_flag=()
 951    must_have_one_noun=()
 952    noun_aliases=()
 953}
 954
 955_git-bug_ls-id()
 956{
 957    last_command="git-bug_ls-id"
 958
 959    command_aliases=()
 960
 961    commands=()
 962
 963    flags=()
 964    two_word_flags=()
 965    local_nonpersistent_flags=()
 966    flags_with_completion=()
 967    flags_completion=()
 968
 969
 970    must_have_one_flag=()
 971    must_have_one_noun=()
 972    noun_aliases=()
 973}
 974
 975_git-bug_ls-label()
 976{
 977    last_command="git-bug_ls-label"
 978
 979    command_aliases=()
 980
 981    commands=()
 982
 983    flags=()
 984    two_word_flags=()
 985    local_nonpersistent_flags=()
 986    flags_with_completion=()
 987    flags_completion=()
 988
 989
 990    must_have_one_flag=()
 991    must_have_one_noun=()
 992    noun_aliases=()
 993}
 994
 995_git-bug_pull()
 996{
 997    last_command="git-bug_pull"
 998
 999    command_aliases=()
1000
1001    commands=()
1002
1003    flags=()
1004    two_word_flags=()
1005    local_nonpersistent_flags=()
1006    flags_with_completion=()
1007    flags_completion=()
1008
1009
1010    must_have_one_flag=()
1011    must_have_one_noun=()
1012    noun_aliases=()
1013}
1014
1015_git-bug_push()
1016{
1017    last_command="git-bug_push"
1018
1019    command_aliases=()
1020
1021    commands=()
1022
1023    flags=()
1024    two_word_flags=()
1025    local_nonpersistent_flags=()
1026    flags_with_completion=()
1027    flags_completion=()
1028
1029
1030    must_have_one_flag=()
1031    must_have_one_noun=()
1032    noun_aliases=()
1033}
1034
1035_git-bug_rm()
1036{
1037    last_command="git-bug_rm"
1038
1039    command_aliases=()
1040
1041    commands=()
1042
1043    flags=()
1044    two_word_flags=()
1045    local_nonpersistent_flags=()
1046    flags_with_completion=()
1047    flags_completion=()
1048
1049
1050    must_have_one_flag=()
1051    must_have_one_noun=()
1052    noun_aliases=()
1053}
1054
1055_git-bug_select()
1056{
1057    last_command="git-bug_select"
1058
1059    command_aliases=()
1060
1061    commands=()
1062
1063    flags=()
1064    two_word_flags=()
1065    local_nonpersistent_flags=()
1066    flags_with_completion=()
1067    flags_completion=()
1068
1069
1070    must_have_one_flag=()
1071    must_have_one_noun=()
1072    noun_aliases=()
1073}
1074
1075_git-bug_show()
1076{
1077    last_command="git-bug_show"
1078
1079    command_aliases=()
1080
1081    commands=()
1082
1083    flags=()
1084    two_word_flags=()
1085    local_nonpersistent_flags=()
1086    flags_with_completion=()
1087    flags_completion=()
1088
1089    flags+=("--field=")
1090    two_word_flags+=("--field")
1091    local_nonpersistent_flags+=("--field")
1092    local_nonpersistent_flags+=("--field=")
1093    flags+=("--format=")
1094    two_word_flags+=("--format")
1095    two_word_flags+=("-f")
1096    local_nonpersistent_flags+=("--format")
1097    local_nonpersistent_flags+=("--format=")
1098    local_nonpersistent_flags+=("-f")
1099
1100    must_have_one_flag=()
1101    must_have_one_noun=()
1102    noun_aliases=()
1103}
1104
1105_git-bug_status_close()
1106{
1107    last_command="git-bug_status_close"
1108
1109    command_aliases=()
1110
1111    commands=()
1112
1113    flags=()
1114    two_word_flags=()
1115    local_nonpersistent_flags=()
1116    flags_with_completion=()
1117    flags_completion=()
1118
1119
1120    must_have_one_flag=()
1121    must_have_one_noun=()
1122    noun_aliases=()
1123}
1124
1125_git-bug_status_open()
1126{
1127    last_command="git-bug_status_open"
1128
1129    command_aliases=()
1130
1131    commands=()
1132
1133    flags=()
1134    two_word_flags=()
1135    local_nonpersistent_flags=()
1136    flags_with_completion=()
1137    flags_completion=()
1138
1139
1140    must_have_one_flag=()
1141    must_have_one_noun=()
1142    noun_aliases=()
1143}
1144
1145_git-bug_status()
1146{
1147    last_command="git-bug_status"
1148
1149    command_aliases=()
1150
1151    commands=()
1152    commands+=("close")
1153    commands+=("open")
1154
1155    flags=()
1156    two_word_flags=()
1157    local_nonpersistent_flags=()
1158    flags_with_completion=()
1159    flags_completion=()
1160
1161
1162    must_have_one_flag=()
1163    must_have_one_noun=()
1164    noun_aliases=()
1165}
1166
1167_git-bug_termui()
1168{
1169    last_command="git-bug_termui"
1170
1171    command_aliases=()
1172
1173    commands=()
1174
1175    flags=()
1176    two_word_flags=()
1177    local_nonpersistent_flags=()
1178    flags_with_completion=()
1179    flags_completion=()
1180
1181
1182    must_have_one_flag=()
1183    must_have_one_noun=()
1184    noun_aliases=()
1185}
1186
1187_git-bug_title_edit()
1188{
1189    last_command="git-bug_title_edit"
1190
1191    command_aliases=()
1192
1193    commands=()
1194
1195    flags=()
1196    two_word_flags=()
1197    local_nonpersistent_flags=()
1198    flags_with_completion=()
1199    flags_completion=()
1200
1201    flags+=("--title=")
1202    two_word_flags+=("--title")
1203    two_word_flags+=("-t")
1204    local_nonpersistent_flags+=("--title")
1205    local_nonpersistent_flags+=("--title=")
1206    local_nonpersistent_flags+=("-t")
1207    flags+=("--non-interactive")
1208    local_nonpersistent_flags+=("--non-interactive")
1209
1210    must_have_one_flag=()
1211    must_have_one_noun=()
1212    noun_aliases=()
1213}
1214
1215_git-bug_title()
1216{
1217    last_command="git-bug_title"
1218
1219    command_aliases=()
1220
1221    commands=()
1222    commands+=("edit")
1223
1224    flags=()
1225    two_word_flags=()
1226    local_nonpersistent_flags=()
1227    flags_with_completion=()
1228    flags_completion=()
1229
1230
1231    must_have_one_flag=()
1232    must_have_one_noun=()
1233    noun_aliases=()
1234}
1235
1236_git-bug_user_adopt()
1237{
1238    last_command="git-bug_user_adopt"
1239
1240    command_aliases=()
1241
1242    commands=()
1243
1244    flags=()
1245    two_word_flags=()
1246    local_nonpersistent_flags=()
1247    flags_with_completion=()
1248    flags_completion=()
1249
1250
1251    must_have_one_flag=()
1252    must_have_one_noun=()
1253    noun_aliases=()
1254}
1255
1256_git-bug_user_create()
1257{
1258    last_command="git-bug_user_create"
1259
1260    command_aliases=()
1261
1262    commands=()
1263
1264    flags=()
1265    two_word_flags=()
1266    local_nonpersistent_flags=()
1267    flags_with_completion=()
1268    flags_completion=()
1269
1270    flags+=("--avatar=")
1271    two_word_flags+=("--avatar")
1272    two_word_flags+=("-a")
1273    local_nonpersistent_flags+=("--avatar")
1274    local_nonpersistent_flags+=("--avatar=")
1275    local_nonpersistent_flags+=("-a")
1276    flags+=("--email=")
1277    two_word_flags+=("--email")
1278    two_word_flags+=("-e")
1279    local_nonpersistent_flags+=("--email")
1280    local_nonpersistent_flags+=("--email=")
1281    local_nonpersistent_flags+=("-e")
1282    flags+=("--name=")
1283    two_word_flags+=("--name")
1284    two_word_flags+=("-n")
1285    local_nonpersistent_flags+=("--name")
1286    local_nonpersistent_flags+=("--name=")
1287    local_nonpersistent_flags+=("-n")
1288    flags+=("--non-interactive")
1289    local_nonpersistent_flags+=("--non-interactive")
1290
1291    must_have_one_flag=()
1292    must_have_one_noun=()
1293    noun_aliases=()
1294}
1295
1296_git-bug_user_ls()
1297{
1298    last_command="git-bug_user_ls"
1299
1300    command_aliases=()
1301
1302    commands=()
1303
1304    flags=()
1305    two_word_flags=()
1306    local_nonpersistent_flags=()
1307    flags_with_completion=()
1308    flags_completion=()
1309
1310    flags+=("--format=")
1311    two_word_flags+=("--format")
1312    two_word_flags+=("-f")
1313    local_nonpersistent_flags+=("--format")
1314    local_nonpersistent_flags+=("--format=")
1315    local_nonpersistent_flags+=("-f")
1316
1317    must_have_one_flag=()
1318    must_have_one_noun=()
1319    noun_aliases=()
1320}
1321
1322_git-bug_user()
1323{
1324    last_command="git-bug_user"
1325
1326    command_aliases=()
1327
1328    commands=()
1329    commands+=("adopt")
1330    commands+=("create")
1331    commands+=("ls")
1332
1333    flags=()
1334    two_word_flags=()
1335    local_nonpersistent_flags=()
1336    flags_with_completion=()
1337    flags_completion=()
1338
1339    flags+=("--field=")
1340    two_word_flags+=("--field")
1341    two_word_flags+=("-f")
1342    local_nonpersistent_flags+=("--field")
1343    local_nonpersistent_flags+=("--field=")
1344    local_nonpersistent_flags+=("-f")
1345
1346    must_have_one_flag=()
1347    must_have_one_noun=()
1348    noun_aliases=()
1349}
1350
1351_git-bug_version()
1352{
1353    last_command="git-bug_version"
1354
1355    command_aliases=()
1356
1357    commands=()
1358
1359    flags=()
1360    two_word_flags=()
1361    local_nonpersistent_flags=()
1362    flags_with_completion=()
1363    flags_completion=()
1364
1365    flags+=("--number")
1366    flags+=("-n")
1367    local_nonpersistent_flags+=("--number")
1368    local_nonpersistent_flags+=("-n")
1369    flags+=("--commit")
1370    flags+=("-c")
1371    local_nonpersistent_flags+=("--commit")
1372    local_nonpersistent_flags+=("-c")
1373    flags+=("--all")
1374    flags+=("-a")
1375    local_nonpersistent_flags+=("--all")
1376    local_nonpersistent_flags+=("-a")
1377
1378    must_have_one_flag=()
1379    must_have_one_noun=()
1380    noun_aliases=()
1381}
1382
1383_git-bug_webui()
1384{
1385    last_command="git-bug_webui"
1386
1387    command_aliases=()
1388
1389    commands=()
1390
1391    flags=()
1392    two_word_flags=()
1393    local_nonpersistent_flags=()
1394    flags_with_completion=()
1395    flags_completion=()
1396
1397    flags+=("--host=")
1398    two_word_flags+=("--host")
1399    local_nonpersistent_flags+=("--host")
1400    local_nonpersistent_flags+=("--host=")
1401    flags+=("--open")
1402    local_nonpersistent_flags+=("--open")
1403    flags+=("--no-open")
1404    local_nonpersistent_flags+=("--no-open")
1405    flags+=("--port=")
1406    two_word_flags+=("--port")
1407    two_word_flags+=("-p")
1408    local_nonpersistent_flags+=("--port")
1409    local_nonpersistent_flags+=("--port=")
1410    local_nonpersistent_flags+=("-p")
1411    flags+=("--read-only")
1412    local_nonpersistent_flags+=("--read-only")
1413    flags+=("--query=")
1414    two_word_flags+=("--query")
1415    two_word_flags+=("-q")
1416    local_nonpersistent_flags+=("--query")
1417    local_nonpersistent_flags+=("--query=")
1418    local_nonpersistent_flags+=("-q")
1419
1420    must_have_one_flag=()
1421    must_have_one_noun=()
1422    noun_aliases=()
1423}
1424
1425_git-bug_root_command()
1426{
1427    last_command="git-bug"
1428
1429    command_aliases=()
1430
1431    commands=()
1432    commands+=("add")
1433    commands+=("bridge")
1434    commands+=("commands")
1435    commands+=("comment")
1436    commands+=("deselect")
1437    commands+=("label")
1438    commands+=("ls")
1439    commands+=("ls-id")
1440    commands+=("ls-label")
1441    commands+=("pull")
1442    commands+=("push")
1443    commands+=("rm")
1444    commands+=("select")
1445    commands+=("show")
1446    commands+=("status")
1447    commands+=("termui")
1448    if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
1449        command_aliases+=("tui")
1450        aliashash["tui"]="termui"
1451    fi
1452    commands+=("title")
1453    commands+=("user")
1454    commands+=("version")
1455    commands+=("webui")
1456
1457    flags=()
1458    two_word_flags=()
1459    local_nonpersistent_flags=()
1460    flags_with_completion=()
1461    flags_completion=()
1462
1463
1464    must_have_one_flag=()
1465    must_have_one_noun=()
1466    noun_aliases=()
1467}
1468
1469__start_git-bug()
1470{
1471    local cur prev words cword
1472    declare -A flaghash 2>/dev/null || :
1473    declare -A aliashash 2>/dev/null || :
1474    if declare -F _init_completion >/dev/null 2>&1; then
1475        _init_completion -s || return
1476    else
1477        __git-bug_init_completion -n "=" || return
1478    fi
1479
1480    local c=0
1481    local flags=()
1482    local two_word_flags=()
1483    local local_nonpersistent_flags=()
1484    local flags_with_completion=()
1485    local flags_completion=()
1486    local commands=("git-bug")
1487    local must_have_one_flag=()
1488    local must_have_one_noun=()
1489    local has_completion_function
1490    local last_command
1491    local nouns=()
1492
1493    __git-bug_handle_word
1494}
1495
1496if [[ $(type -t compopt) = "builtin" ]]; then
1497    complete -o default -F __start_git-bug git-bug
1498else
1499    complete -o default -o nospace -F __start_git-bug git-bug
1500fi
1501
1502# ex: ts=4 sw=4 et filetype=sh