Konvt / simsh

A simple Linux Shell written in Modern C++.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

simsh - The simple implementation of shell

Contents

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 run simsh

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 -S . -B build && cmake --build build

Binary

Since some functions rely on glibc, the binary files are not guaranteed to run correctly.

For more details, refer to the build environment declarations in Releases.

How to use

Just like using bash.

You can pass command line arguments at startup to execute a single statement.

./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.

(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.

./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::rangesstd::format

使用 ./simsh 运行程序。

xmake(推荐)

xmake run simsh

Makefile

make -j4 all

CMake

项目的 CMakeLists.txt 是由 xmake 生成的,不保证绝对可用;如果你有 xmake 且更偏好使用 CMake,可以使用 xmake project -k cmake 生成 CMakeLists.txt

cmake -S . -B build && cmake --build build

Binary

因为部分函数依赖于 glibc,因此不保证二进制文件能够正常运行。

详情可以参照 Releases 中的构建环境声明。

如何使用

就像使用 bash 一样。

可以在启动时传入命令行参数,以执行单条语句。

./simsh -c "whoami && pwd"  # 单条语句必须带有 -c 参数
./simsh "whoami" "&&" "pwd" # 或者提前分割为多条语句传入,此时不需要 -c 参数

也可以从文件读取命令。

(echo "whoami && pwd" > ./script.txt) && ./simsh ./script.txt
# 没有后缀要求,只要求文件是文本格式

此外,simsh 在遇到特殊标记(即 $$~)时,会将其展开为当前程序的 pid 或用户家目录的绝对路径。

./simsh -c "echo ~ && echo \$\$"

如果以 root 用户身份运行,默认的 simsh::CLI 对象会将命令提示符替换为没有颜色、且以 # 结尾的格式。

About

A simple Linux Shell written in Modern C++.

License:MIT License


Languages

Language:C++ 96.6%Language:CMake 1.6%Language:Makefile 1.2%Language:Lua 0.6%