-
Notifications
You must be signed in to change notification settings - Fork 8k
comprehensive Unix-like shell features for console system (IDFGH-16704) #17793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
👋 Hello jimmyw, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
d24aa4f to
a9e53fc
Compare
- Add termios state tracking in console VFS layer - Implement EOF character detection in console_read() - Store and synchronize c_lflag and c_cc[] between tcgetattr/tcsetattr - Enable canonical mode and EOF handling in console example - Return 0 (EOF) when configured EOF character is detected in canonical mode This enables proper Ctrl+D handling for interactive console applications, allowing users to send EOF signals to terminate input or exit programs gracefully using standard POSIX terminal behavior.
Add VFS layer support for POSIX-compatible pipes with: - Standard pipe() syscall implementation - Blocking/non-blocking I/O with select() support - Thread-safe operations using FreeRTOS primitives - Proper resource management and error handling
Add new functions to retrieve and iterate through registered console commands: - esp_console_get_by_name(): Find command by name - esp_console_get_iterate(): Iterate through all commands This enables programmatic access to the console command registry, useful for dynamic command introspection and tooling. Refactored internal cmd_item_t structure to embed esp_console_cmd_t for cleaner API implementation.
b2d1484 to
2b6e2f8
Compare
Add asynchronous command execution with I/O redirection: - New esp_console_run_on_task() API to execute commands on FreeRTOS tasks - Support for custom stdin/stdout/stderr file pointers - Configurable stack size and priority per command - Task lifecycle management functions (wait, query status, cleanup) - Optional CONSOLE_COMMAND_ON_TASK config to enable feature This enables non-blocking command execution, pipelines, and better resource management for long-running console commands.
Add new esp_shell component providing Unix-like shell functionality: - Pipeline support with '|' operator for command chaining - File output with support for '>' or '>>' for append. - Multiple command operators: ';' (continue), '&&' (break on fail), '||' (break on success) - Asynchronous command execution using console task API - Real-time I/O handling with select() for stdin/stdout/stderr - Proper resource management and error handling - Support for Ctrl+D EOF detection, will support escaping of if a program like grep Enables complex command sequences and data flow between commands similar to traditional Unix shells.
Add Unix-like shell functionality to demonstrate console capabilities: - Implement tee, cat, echo, and other shell commands - Add esp_shell component for shell command execution - Enable task-based command execution for pipelines - Demonstrate pipe usage and I/O redirection Shows practical usage of console task API and VFS pipe features.
|
Hello @jimmyw, Thanks a lot for this contribution! At first glance, it looks like a really nice addition to the console component. The first thing I would suggest is to break it into several smaller PRs to facilitate the merging process. Secondly, it seems to me that you are creating this PR against an older version of esp-idf. I went through the changes briefly and noticed in vfs_pipe.c: The way I have been working on a refactor of the console component of esp-idf for the past few months. Which brings me to my last point. I think it might be more interesting to merge the console related changes of this PR directly in those newly created components. This way, the "new" console will implement this shell feature. And since I will replace the implementation of the esp-idf console with the new components, this feature will - by extension - also be available in the esp-idf console. Here is the links to the components:
|
|
I will try to take some time this week to continue and review in more details the submitted feature. |
|
Hi, thanks for feedback. You are right, I wrote this feature on 5.4 that we currently use in production, and ported it forward just for this attempt to upstream it. This PR was mostly a request for feedback (DRAFT), to see if there is any interest in this at all, not really meant for merging as is. That's also why i did not break it up into separate commits, just so people could see how things are combined. I think your new modular approach is a really good idea, and are happy to contribute with your guidance. Any suggestion where to start? |
|
+1 +1 +1 +1 for this please!
…On Tuesday, 11 November 2025 at 11:35, Jimmy Wennlund ***@***.***> wrote:
jimmyw left a comment [(espressif/esp-idf#17793)](#17793 (comment))
Hi, thanks for feedback.
You are right, I wrote this feature on 5.4 that we currently use in production, and ported it forward just for this attempt to upstream it.
This PR was mostly a request for feedback (DRAFT), to see if there is any interest in this at all, not really meant for merging as is. That's also why i did not break it up into separate commits, just so people could see how things are combined.
I think your new modular approach is a really good idea, and are happy to contribute with your guidance.
Any suggestion where to start?
—
Reply to this email directly, [view it on GitHub](#17793 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAYT7GBKCA6WP4NMVGKSRH334GUUXAVCNFSM6AAAAACKUVOVVKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTKMJVHA3TCMZYGQ).
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
I will take a deeper look into your changes this week. I'll reach back after that and we will see then :) But I guess starting by isolating the changes to VFS (pipe addition) into a separate PR might be a good start. |
|
@jimmyw, just a little update:
The only thing remaining to solve in order to completely integrate this nice addition is how to integrate I think I could update I am sure that we will find more problems as we go but this approach seems like a good way to go. Let me know what you think. I you want to take a look at the components that are now replacing the old idf console, you can check: https://github.com/espressif/idf-extra-components/tree/master/esp_cli |
Description
This pull request introduces a comprehensive Unix-like shell component to ESP-IDF's console system, along with a VFS pipe implementation.
Background: at my company we have built a home battery energy storage system. It have been growing a lot, and we use the esp_console features extensively, even remotely over mqtt, in a local webserver interface, and for CI testing. Some commands generate a lot of data, so there was a long time dream of me, to be able to use tools like grep or less to be more efficient.
Major Features Added
Thread-Safe VFS Pipe Implementation (vfs_pipe.c)
This is a self containing feature for POSIX Compatibility: Full pipe() syscall implementation with
standard semantics
Advanced I/O Support: Blocking/non-blocking operations with select() integration
Thread Safety: FreeRTOS-based synchronization preventing race conditions
Resource Management: Proper cleanup and error handling for production use
Enhanced Console API (esp_console.h)
Task-Based Execution: New esp_console_run_on_task() for asynchronous command execution
Process Management: esp_console_wait_task() and esp_console_task_free() for task lifecycle
Status Monitoring: esp_console_task_is_running() for non-blocking status checks
Command Access: esp_console_get_command_list() for programmatic command introspection
This optional feature can enable to use smaller stack for the console task, and adjustable stack
sizes for commands that run in their own stack only when active.
Shell Component (shell.c)
Pipeline Support: Full implementation of command pipelines using | operator
Command Chaining: Support for ; (continue), && (break on fail), || (break on success) operators
File Redirection: Output redirection with > (write) and >> (append) operators
Interactive Features: Ctrl+D detection for EOF handling, proper stdin/stdout/stderr management
Async Execution: Task-based command execution with proper lifecycle management.
This is a work in progress as a lot of more features can be added, like run tasks in the background.
Updated advanced console example (console_example_main.c)
Now supports using the new shell extension leveraging support for shell component as well as adding commands like cat, echo, true, false, tee and grep
Testing
There is no tests implementation written yet, as i'm not sure of any interest in upstreaming these changes. If there seems to be interest, i will definitely add that before merge.
Examle
Checklist
Before submitting a Pull Request, please ensure the following: