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

Request: Support aliases in argcompletion #222

Open
jonasstoetzel opened this issue Aug 4, 2017 · 5 comments
Open

Request: Support aliases in argcompletion #222

jonasstoetzel opened this issue Aug 4, 2017 · 5 comments

Comments

@jonasstoetzel
Copy link

Hi,

For my-awesome-script, we currently don't do any work to make this work with aliases. If you need this, I'd suggest opening a new issue to request the feature.

There it is! :-)
I currently have a script at /path/to/file which takes two positional arguments arg1 + arg2.
The script is usually called via alias a=python3 /path/to/file arg1 and arg2 should be completable. It works fine when I type it out, but it would be really nice if I could use argcomplete with my alias.

Thanks!

@evanunderscore
Copy link
Collaborator

From my limited reading it seems this is a general problem with completion and not something we should deal with inside argcomplete. Here a few of the pages I've looked at:

@jonasstoetzel
Copy link
Author

The suggestions for arg2 are computed inside of /path/to/file though and I don't know how to do that in bash (getting suggestions from a single file).
It would be a lot easier if this could be done in argcomplete. Is there any chance this could be implemented? I'm sure lots of users would benefit from this feature if it existed.

@evanunderscore
Copy link
Collaborator

Looking at this a bit more closely, we would at least have to replace the alias in COMP_LINE for any generic solution to work, including in global completion where the above links don't apply. I don't have any time to work on this, but I'd be happy to help where I can if you want to work on a solution (provided @kislyuk is interested in merging this feature in some form).

@jonasstoetzel
Copy link
Author

I'm afraid I don't know how to approach this.
I managed to circumvent this issue by defining

However, this does not work with aliases. The function defined in .bashrc acts speeds things up though.

@kislyuk
Copy link
Owner

kislyuk commented Feb 13, 2018

I'm not sure if we want to accommodate aliases. In case we do, here is how the git bashcomp shellcode does it:

__git_complete ()
{
    local wrapper="__git_wrap${2}";
    eval "$wrapper () { __git_func_wrap $2 ; }";
    complete -o bashdefault -o default -o nospace -F $wrapper $1 2> /dev/null || complete -o default -o nospace -F $wrapper $1
}
__git_func_wrap ()
{
    local cur words cword prev;
    _get_comp_words_by_ref -n =: cur words cword prev;
    $1
}

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

3 participants