Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong completion when executed in git-bash (Mingw) session #2348

Open
gturi opened this issue Jul 22, 2023 · 1 comment
Open

Wrong completion when executed in git-bash (Mingw) session #2348

gturi opened this issue Jul 22, 2023 · 1 comment

Comments

@gturi
Copy link

gturi commented Jul 22, 2023

Asking yargs to generate the completion in a git-bash session on windows produces the following completion function:

_main_yargs_completions()
{
    local cur_word args type_list

    cur_word="${COMP_WORDS[COMP_CWORD]}"
    args=("${COMP_WORDS[@]}")

    # ask yargs to generate completions.
    type_list=$(C:\Program Files\nodejs\node_modules\my-program\bin\main --get-yargs-completions "${args[@]}")

    COMPREPLY=( $(compgen -W "${type_list}" -- ${cur_word}) )

    # if no match was found, fall back to filename completion
    if [ ${#COMPREPLY[@]} -eq 0 ]; then
      COMPREPLY=()
    fi

    return 0
}
complete -o bashdefault -o default -F _main_yargs_completions main

The path to the program is returned windows style instead of unix style.

By replacing C:\Program Files\nodejs\node_modules\my-program\bin\main with /c/Program Files/nodejs/node_modules/my-program/bin/main everything works correctly.

I am using yargs 17.7.2

@shadowspawn
Copy link
Member

shadowspawn commented Jul 23, 2023

When I saw the title I thought MinGW might be difficult, but just a path change seems possible.

The path support is complicated by a shim layer to support the multiple runtime environments. The place the substitution occurs is:

yargs/lib/completion.ts

Lines 352 to 357 in e517318

const name = this.shim.path.basename($0);
// add ./ to applications not yet installed as bin.
if ($0.match(/\.js$/)) $0 = `./${$0}`;
script = script.replace(/{{app_name}}/g, name);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants