# shellcheck shell=bash disable=2034

___x_cmd_advise_complete_onsh(){
    local op="$1"
    case "$op" in
        code|run)   shift; ___x_cmd_advise_complete_onsh_"$op" "$@" ;;
        *)          ___x_cmd_advise_complete_onsh_run "$@" ;;
    esac
}

___x_cmd_advise_complete_onsh_run(){
    local cur="${*: -1}"
    local COMP_WORDS=("$@");    local COMP_LINE="$*"
    local COMP_CWORD="$#";      COMP_CWORD=$((COMP_CWORD-1))

    local x_=;  ___x_cmd_advise___main __run_filepath_ "$1" || ___x_cmd_advise___main __run_filepath_ x-cmd "$1" || return $?
    shift;
    ___x_cmd_advise_complete___gen_wordlist \
        "$___X_CMD_ROOT_MOD/advise/lib/awk/advise/advise.compgen_wordlist.onsh.awk" \
        "$x_" "$@"
}

___x_cmd_advise_complete_onsh_code(){
    printf "%s\n" "from xonsh.completers.completer import add_one_completer
from xonsh.completers.tools import contextual_command_completer

@contextual_command_completer
def ___x_cmd_advise_run_onsh(context):
    \"\"\"x-cmd advise completer\"\"\"
    from json import loads
    from xonsh.completers.tools import sub_proc_get_output, RichCompletion

    output, _ = sub_proc_get_output(
        'bash', 'x', 'advise', 'complete', 'onsh', 'run', *[a.value if a.value != \$HOME + \"/.x-cmd.root/bin/___x_cmdexe_exp\" + \$___x_cmd_xonsh___bin_suffix else 'x' for a in context.args], context.prefix.translate(str.maketrans('', '', '\'\"'))
    )

    if not output:
        return

    for c in loads(output):
        yield RichCompletion(
            c[\"Value\"],
            display=c[\"Display\"],
            description=c[\"Description\"],
            prefix_len=len(context.raw_prefix),
            append_closing_quote=False,
            style=c[\"Style\"],
        )

add_one_completer('advise', ___x_cmd_advise_run_onsh, 'start')"
}
