function _vm() {
    local opts comp_res cur
    opts=$( command vm complete "$COMP_CWORD" "${COMP_WORDS[@]}" 2>/dev/null )
    comp_res=$?
    if [[ $comp_res -eq 64 ]]; then
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        _filedir
        return 0
    elif [[ $comp_res -gt 200 ]]; then
        _command_offset "$((comp_res - 200))"
        return
    else
        mapfile -t OPTS <<< "$opts"
        mapfile -t COMPREPLY < <( compgen -W "${OPTS[*]}" -- ${COMP_WORDS[COMP_CWORD]} )
    fi
}
complete -F _vm vm
