Skip to content

Support for partial commands #992

@ralequi

Description

@ralequi

Some shells accept and interpret partial commands and it would be a great feature to be included.

Let's take a look an example:
By default cmd2 includes quit command, which is used to end the cmd-session.
In many scenarios, it would be useful to allow the user just write q to get the same functionality.
Of course cmd2 support many ways of doing this, such as alias, macros or shortcuts, however, all of them should be created "manually" for each command.

Of course, there may be conflicts such not always the first letter could be used.
Let's say we have 2 different commands called stop and show (that can be found in many shells that support this kind of things).
In this scenario, it would be great to automatically cmd2 allow using sh or sho as an alias of the command show, in the same way as st or sto as alias of stop. Of course s have 2 possible candidates, so it may be considered just an invalid/incomplete command.

A possible implementation:
One possible implementation that may even work with subcommands is simple:
1 - the user input a command
2.1 - If the command exists or is an alias execute it as always
2.2 - if the commands does not exists, call autocomplete
3.1 - if the autocomplete returns none or more than 1 results, return invalid command as always
3.2 - if the autocomplete returns exactly one result, try to run that one and store it as if the user has written it down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions