argcomplete
argcomplete copied to clipboard
Request: Support aliases in argcompletion
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!
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:
- https://stackoverflow.com/questions/342969/how-do-i-get-bash-completion-to-work-with-aliases
- https://unix.stackexchange.com/questions/4219/how-do-i-get-bash-completion-for-command-aliases
- https://ubuntuforums.org/showthread.php?t=733397
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.
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).
I'm afraid I don't know how to approach this. I managed to circumvent this issue by defining
- a function in
.bashrc
which calls/path/to/file
and - a wrapper in
/etc/bash_completion.d/
inspired by "A Basic Example" from https://debian-administration.org/article/317/An_introduction_to_bash_completion_part_2
However, this does not work with aliases. The function defined in .bashrc
acts speeds things up though.
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
}