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

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

    case $prev in
    -e|--exclude)
        # Regex pattern completion - let user type their own
        return
        ;;
    -n|--name|-f|--file)
        _filedir
        return
        ;;
    -b|--bootloader)
        COMPREPLY=($(compgen -W 'isolinux grub' -- "$cur"))
        return
        ;;
    esac

    if [[ "$cur" == *=* ]]; then
        local opt="${cur%%=*}"
        cur="${cur#*=}"
        case $opt in
        --exclude)
            # Regex pattern completion - let user type their own
            return
            ;;
        --name|--file)
            _filedir
            return
            ;;
        --bootloader)
            COMPREPLY=($(compgen -W 'isolinux grub' -- "$cur"))
            return
            ;;
        *) ;;
        esac
    fi

    if [[ "$cur" == --* ]]; then
        COMPREPLY=($(compgen -W '--bootloader --exclude --name --verbose --help --version' -- "$cur"))
    elif [[ "$cur" == -* ]]; then
        COMPREPLY=($(compgen -W '-b -e -n -v' -- "$cur"))
    else
        # Complete .sb module files
        _filedir '@(sb|SB)'
    fi

}

complete -F _sb2iso sb2iso
