_chroot2sb() {
    local cur prev words cword
    _init_completion -n = || return

    if [[ ${words[@]} =~ --help ]] || [[ ${words[@]} =~ --version ]]; then
        return
    fi

    case $prev in
    -d)
        _filedir
        return
        ;;
    -n)
        _filedir
        return
        ;;
    -l)
        COMPREPLY=($(compgen -W '00 01 02 03 04 05 06 07 08 09' -- "$cur"))
        return
        ;;
    esac

    if [[ "$cur" == *=* ]]; then
        local opt="${cur%%=*}"
        cur="${cur#*=}"
        case $opt in
        --directory)
            _filedir
            return
            ;;
        --name)
            _filedir
            return
            ;;
        --level)
            COMPREPLY=($(compgen -W '00 01 02 03 04 05 06 07 08 09' -- "$cur"))
            return
            ;;
        *) ;;
        esac
    fi

    if [[ "$cur" == --* ]]; then
        COMPREPLY=($(compgen -W '--bext --comp --directory --name --level' -- "$cur"))
    elif [[ "$cur" == -* ]]; then
        COMPREPLY=($(compgen -W '-b -c -d -n -l' -- "$cur"))
    else
        COMPREPLY=($(compgen -W '--bext --comp --directory --name --level' -- "$cur"))
    fi

}

complete -F _chroot2sb chroot2sb
