argcomplete
argcomplete copied to clipboard
Feature request: Option to not list argument aliases in the completion
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.
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.
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?
Not sure, you may have to add some more logic to my_argparse so it collects subcommand names and aliases separately.
About subcommands, does argcomplete support argparse subcommands?
It does. Please open a new issue if you have problems that are not related to this feature request.