argcomplete icon indicating copy to clipboard operation
argcomplete copied to clipboard

Feature request: Option to not list argument aliases in the completion

Open redstreet opened this issue 10 years ago • 5 comments

It would be nice to have an option to not list aliases in the completion list. Many applications with rich command line interfaces (like svn) tend to liberally use aliases for subcommands. These are very useful as shortcuts (eg: svn list is same as svn ls) for advanced users. However, it's confusing and noisy when all these are listed as completions.

However, some times, listing aliases might be useful. For example, svn blame has {praise, annotate, ann} as aliases, and the user might want to see these.

So perhaps the ultimate solution is to allow for fine-grained control of listing aliases. But for now, what would be useful is a global "includeAliases = True/False" option passed to argcomplete.

(As a side note, zsh is again light years ahead of bash completion in this regard: it understands aliases.)

I would think this would be easy to accomplish, given that aliases to argparse are specified separately, but I might be mistaken.

redstreet avatar Aug 22 '13 21:08 redstreet

Yes, should be pretty easy. Just make a new kwarg for argcomplete.autocomplete() and only add the first item instead of the whole list in https://github.com/kislyuk/argcomplete/blob/master/argcomplete/init.py#L219

                completions += [option for option in action.option_strings if option.startswith(cword_prefix)]

and a test of course.

kislyuk avatar Aug 23 '13 06:08 kislyuk

Great, thanks for the pointer! The line you pointed to works fine for options, but not when there are subcommands with aliases. Looks like Line 217 above is used for this. However, parser._actions in that line (coming from here) is a flattened list of subcommands and subcommand aliases. Any hints on how to get a non-flattened list of this sort?

redstreet avatar Aug 23 '13 08:08 redstreet

Not sure, you may have to add some more logic to my_argparse so it collects subcommand names and aliases separately.

kislyuk avatar Aug 23 '13 16:08 kislyuk

About subcommands, does argcomplete support argparse subcommands?

xavier83 avatar Jul 08 '17 13:07 xavier83

It does. Please open a new issue if you have problems that are not related to this feature request.

evanunderscore avatar Jul 08 '17 13:07 evanunderscore