Shell Enhancements
Posted: Sat Apr 09, 2016 9:27 pm
I added some features to the basic shell. They are a command history and command completion when you press the "tab" key. I also removed some extra code for exit that seemed redundant and I made the usage function in shell.c and shell_cmd.c public. The patches for each change are attached. They are:
01-shellExit.patch - Remove the explicit exit code from the command processing section of the shell thread since it is now part of the shell_local_commands. Also removed the extra printing of exit in the help message.
02-commandHistory.patch - Added command history functionality. It saves the current command line to a buffer when you press "enter". To navigate the history use ^P and ^N.
03-commandCompletions.patch - Added command completion based on the shell_local_commands and the user-specified commands when the "tab" key is pressed.
04-escapeSequence.patch - Added escape sequence processing to shellGetLine. This is required to use the up and down arrow keys for the history patch. Those are the only escape sequences that it handles at the moment.
05-shellUsage.patch - Moved the usage function to the shellUsage macro in shell.h so that it can be used by user-specified commands. Made all of the commands defined in shell.c and shell_cmd.c use the new macro for their usage message.
Also, given the configurations that can be specified for the shell, would it make sense to add a shellconf.h file to projects and include it from shell.h to allow the user to easily change the default defines? Right now I've just added them to my chconf.h when I needed to use a different value, but I think a separate file is better to avoid cluttering the chconf.h.
I used the Github mirror and git to generate the patches, so if you need them in a different format I can see about how to create them against the SVN repo. Just let me know.
01-shellExit.patch - Remove the explicit exit code from the command processing section of the shell thread since it is now part of the shell_local_commands. Also removed the extra printing of exit in the help message.
02-commandHistory.patch - Added command history functionality. It saves the current command line to a buffer when you press "enter". To navigate the history use ^P and ^N.
03-commandCompletions.patch - Added command completion based on the shell_local_commands and the user-specified commands when the "tab" key is pressed.
04-escapeSequence.patch - Added escape sequence processing to shellGetLine. This is required to use the up and down arrow keys for the history patch. Those are the only escape sequences that it handles at the moment.
05-shellUsage.patch - Moved the usage function to the shellUsage macro in shell.h so that it can be used by user-specified commands. Made all of the commands defined in shell.c and shell_cmd.c use the new macro for their usage message.
Also, given the configurations that can be specified for the shell, would it make sense to add a shellconf.h file to projects and include it from shell.h to allow the user to easily change the default defines? Right now I've just added them to my chconf.h when I needed to use a different value, but I think a separate file is better to avoid cluttering the chconf.h.
I used the Github mirror and git to generate the patches, so if you need them in a different format I can see about how to create them against the SVN repo. Just let me know.