# This script enables tab completion for hab in bash. It requires bash 4.4+.
# https://click.palletsprojects.com/en/8.1.x/shell-completion/

# To enable tab completion source this script in your .bashrc script.
# `. /c/Program\ Files/Python39/Scripts/.hab-complete.bash`
# `. /usr/local/bin/.hab-complete.bash`

# This script below was generated by running `_HAB_COMPLETE=bash_source hab > .hab-complete.bash`

_hab_completion() {
    local IFS=$'\n'
    local response

    response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _HAB_COMPLETE=bash_complete $1)

    for completion in $response; do
        IFS=',' read type value <<< "$completion"

        if [[ $type == 'dir' ]]; then
            COMPREPLY=()
            compopt -o dirnames
        elif [[ $type == 'file' ]]; then
            COMPREPLY=()
            compopt -o default
        elif [[ $type == 'plain' ]]; then
            COMPREPLY+=($value)
        fi
    done

    return 0
}

_hab_completion_setup() {
    complete -o nosort -F _hab_completion hab
}

_hab_completion_setup;
