Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/konvt/simsh
A simple Linux Shell written in Modern C++.
https://github.com/konvt/simsh
cmake cpp cpp20 linux linux-shell makefile modern-cpp shell xmake
Last synced: 14 days ago
JSON representation
A simple Linux Shell written in Modern C++.
- Host: GitHub
- URL: https://github.com/konvt/simsh
- Owner: Konvt
- License: mit
- Created: 2024-06-21T06:47:28.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-26T16:56:02.000Z (2 months ago)
- Last Synced: 2025-01-20T17:17:19.079Z (14 days ago)
- Topics: cmake, cpp, cpp20, linux, linux-shell, makefile, modern-cpp, shell, xmake
- Language: C++
- Homepage:
- Size: 200 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# simsh - The simple implementation of shell
**Contents**
- [simsh - The simple implementation of shell](#simsh---the-simple-implementation-of-shell)
- [Features](#features)
- [How to build](#how-to-build)
- [xmake (recommended)](#xmake-recommended)
- [Makefile](#makefile)
- [CMake](#cmake)
- [Binary](#binary)
- [How to use](#how-to-use)
- [simsh - Shell 的简单实现 - zh\_cn](#simsh---shell-的简单实现---zh_cn)
- [特点](#特点)
- [如何构建](#如何构建)
- [xmake(推荐)](#xmake推荐)
- [Makefile](#makefile-1)
- [CMake](#cmake-1)
- [Binary](#binary-1)
- [如何使用](#如何使用)A simple Linux Shell written in Modern C++.
## Features
- Supports nested statements
- Supports most redirection functionalities, including pipes
- Syntax parsing based on recursive descent method
- Modular design
- Adheres to Modern C++ standards## How to build
The syntax standard used is C++20 (with `ranges` and `format`), so the compiler required for building needs to be at least g++13 or clang14.The project provides three build methods, **but it is recommended not to use more than one build tool simultaneously.**
Each method assumes the compilation tool **fully supports** `std::ranges` or `std::format`.
Run the program with `./simsh`.
### xmake (recommended)
```xmake
xmake run simsh
```
### Makefile
```makefile
make -j4 all
```
### CMake
The project's `CMakeLists.txt` is generated by `xmake`, and its usability is not guaranteed; if you have `xmake` and prefer using `CMake`, you can use `xmake project -k cmake` to generate `CMakeLists.txt`.
```cmake
cmake -S . -B build && cmake --build build
```
### Binary
Since some functions rely on `glibc`, the [binary files](https://github.com/Konvt/simsh/releases/tag/v0.1.1) are not guaranteed to run correctly.For more details, refer to the build environment declarations in [Releases](https://github.com/Konvt/simsh/releases).
## How to use
Just like using bash.You can pass command line arguments at startup to execute a single statement.
```sh
./simsh -c "whoami && pwd" # Single statement must include the -c parameter
./simsh "whoami" "&&" "pwd" # Or split into multiple statements in advance, no -c parameter needed
```You can also read commands from a file.
```sh
(echo "whoami && pwd" > ./script.txt) && ./simsh ./script.txt
# No specific extension required, just needs to be a text format file
```Additionally, `simsh` will expand special symbols (i.e., `$$` and `~`) to the current program's `pid` or the user's home directory path, respectively.
```sh
./simsh -c "echo ~ && echo \$\$"
```If run as the `root` user, the default `simsh::CLI` object will change the command prompt to a colorless format ending with `#`.
- - -
# simsh - Shell 的简单实现 - zh_cn
一个由 Modern C++ 编写的、简单的 Linux Shell。
## 特点
- 支持嵌套语句
- 支持包括管道在内的大部分重定向功能
- 基于递归下降法进行语法解析
- 模块化设计
- 遵循 Modern C++ 规范## 如何构建
使用的语法标准为 C++20(with `ranges` and `format`),故构建时的编译器需要至少是 g++13,或 clang14项目提供了三种构建方式,**但这里建议不要同时使用两种及以上的构建工具**。
每种方式都假定使用的编译工具**已完全支持** `std::ranges` 或 `std::format`。
使用 `./simsh` 运行程序。
### xmake(推荐)
```xmake
xmake run simsh
```
### Makefile
```makefile
make -j4 all
```
### CMake
项目的 `CMakeLists.txt` 是由 `xmake` 生成的,不保证绝对可用;如果你有 `xmake` 且更偏好使用 `CMake`,可以使用 `xmake project -k cmake` 生成 `CMakeLists.txt`。
```cmake
cmake -S . -B build && cmake --build build
```
### Binary
因为部分函数依赖于 `glibc`,因此不保证[二进制文件](https://github.com/Konvt/simsh/releases/tag/v0.1.1)能够正常运行。详情可以参照 [Releases](https://github.com/Konvt/simsh/releases) 中的构建环境声明。
## 如何使用
就像使用 bash 一样。可以在启动时传入命令行参数,以执行单条语句。
```sh
./simsh -c "whoami && pwd" # 单条语句必须带有 -c 参数
./simsh "whoami" "&&" "pwd" # 或者提前分割为多条语句传入,此时不需要 -c 参数
```也可以从文件读取命令。
```sh
(echo "whoami && pwd" > ./script.txt) && ./simsh ./script.txt
# 没有后缀要求,只要求文件是文本格式
```此外,`simsh` 在遇到特殊标记(即 `$$` 和 `~`)时,会将其展开为当前程序的 `pid` 或用户家目录的绝对路径。
```sh
./simsh -c "echo ~ && echo \$\$"
```如果以 `root` 用户身份运行,默认的 `simsh::CLI` 对象会将命令提示符替换为没有颜色、且以 `#` 结尾的格式。