https://github.com/bang-olufsen/yash
Yash - Yet Another Shell
https://github.com/bang-olufsen/yash
cplusplus cpp cpp11 embedded header-only minimal shell
Last synced: 4 months ago
JSON representation
Yash - Yet Another Shell
- Host: GitHub
- URL: https://github.com/bang-olufsen/yash
- Owner: bang-olufsen
- License: mit
- Created: 2021-07-16T13:25:11.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-01-27T08:59:23.000Z (over 2 years ago)
- Last Synced: 2024-04-14T07:41:10.531Z (about 1 year ago)
- Topics: cplusplus, cpp, cpp11, embedded, header-only, minimal, shell
- Language: C++
- Homepage:
- Size: 4 MB
- Stars: 4
- Watchers: 22
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Yash - Yet Another Shell
[](https://github.com/bang-olufsen/yash/actions/workflows/build.yml) [](https://coveralls.io/github/bang-olufsen/yash?branch=main) [](https://github.com/bang-olufsen/yash/actions/workflows/codeql-analysis.yml) [](https://lgtm.com/projects/g/bang-olufsen/yash/context:cpp) [](LICENSE)
Yash is a C++20 header-only minimal shell for embedded devices with support for command completion.

It was created as a serial port shell but can be used for other interfaces as well by using `setPrint()`. The prompt can be customized with `setPrompt()` and commands are added as a std::array which can be constexpr to save memory. The command history size can be adjusted by the constructor (default 10). An example can be seen below (taken from [example.cpp](https://github.com/bang-olufsen/yash/blob/main/example/example.cpp) and what is demoed in the image above).
```cpp
#include
#includevoid i2c(const std::string_view command, Yash::CommandArgs args)
{
if (command == "read")
printf("i2cRead(%s, %s, %s)\n", args[0].data(), args[1].data(), args[2].data());
else if (command == "write")
printf("i2cWrite(%s, %s, %s)\n", args[0].data(), args[1].data(), args[2].data());
}void info(Yash::CommandArgs /* unused */)
{
printf("info()\n");
}int main()
{
static constexpr Yash::Config config { .maxRequiredArgs = 3, .commandHistorySize = 10 };
static constexpr auto commands = std::to_array({
{ "i2c read", "I2C read ", [](Yash::CommandArgs args) { i2c("read", args); }, 3 },
{ "i2c write", "I2C write ", [](Yash::CommandArgs args) { i2c("write", args); }, 3 },
{ "info", "System info", [](const auto args) { info(args); }, 0 }, // OR auto if preffered
});Yash::Yash yash(commands);
yash.setPrint([&](const char* str) { printf("%s", str); });
yash.setPrompt("$ ");while (true)
yash.setCharacter(getch());return 0;
}
```