Invalid Command name when command starts with same character as a shortcut.
See original GitHub issueI don’t know if quit already exists in the library, but I have a command do_quit that just exits out of the command line.
And then I use shortcuts to shortcut q -> quit and exit -> quit.
However, doing this results in this error:
ValueError: Invalid command name 'quit': cannot start with a shortcut: @@, ?, !, @, q
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Invalid command name "exit" while executing "exit"
from PyCharm. I tried running the same script in IDLE (Python 3.6) and Terminal (Python 2.7), and they all produced the same problem...
Read more >ISPD224 Invalid command - IBM
The command name is invalid. Command names must start with an alphabetic character, or @, #, or $. The remaining characters must be...
Read more >command name is invalid | The AI Search Engine You Control
Press Windows + X, locate and open Command Prompt (Admin). ( See Image 6) Image 6: Open Command Prompt (Admin) b.
Read more >cmd2/cmd2.py at master · python-cmd2/cmd2 - GitHub
Special-character shortcut commands (beyond cmd's "?" and "!") ... Verify commands don't have invalid names (like starting with a shortcut).
Read more >Documentation - iTerm2 - macOS Terminal Replacement
You can search by tab title, command name, host name, user name, profile name, ... When you first start iTerm2, a window opens...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@xNinjaKittyx There is a distinction between shortcuts and aliases that makes shortcuts very convenient. A shortcut does not require a space between it and its arguments. So the following command lines are valid:
!ls?macroThe parser checks if a command line begins with a shortcut, and if so, splits them as follows:
! ls? macroBecause of this, there is no way to run your
quitcommand directly.Since
quitbegins with the shortcutq,the parser splits it this way:q uitAt that point, the parser resolvesqintoquitwhich results in a final command line ofquit uitIn your case, the behavior was being masked because your
quitfunction probably just ignores the argumentuitbeing passed to it.If your application had another command that started with
qbut wasn’t related toquit, you would have seen the issue faster. I added the error message to 0.9.16 to prevent this exact problem.If you still want to type
qand runquit, then you want an alias. For your shortcuts, you will run two commands.alias create q quitalias create exit quitYou can create these at startup in a few ways:
self.runcmds_plus_hooks()with these commands in a list.You will see the output of the alias creation when the application starts.
If you don’t want to see that output, then redirect the commands to /dev/null or your operating system’s equivalent. You can also pass
add_to_history=Falsetoself.runcmds_plus_hooks()if you don’t want the alias creation commands to be stored in history.By the way.
cmd2already has ado_quit()method. If ours already does what you need, then you can remove yours.Cool, I like that one. Thanks everyone.