๐Ÿš ShellKit (libc + pysh)

June 27, 2025 ยท View on GitHub

Learn how echo works from shell to syscall โ€” all in one Python playground.

Python Version PyPI version License: MIT Platform Languages CI

English | ็ฎ€ไฝ“ไธญๆ–‡ | ๆ—ฅๆœฌ่ชž | ํ•œ๊ตญ์–ด


๐Ÿ“– Overview

ShellKit is a Unix-like educational terminal toolkit consisting of two main components:

  • Libc: A Python-based simulation of core C library calls such as syscall, write, and printf. It walks through the transition from user space to kernel space.
  • Pysh: An interactive shell built on top of Libc, featuring internal commands, REPL execution, cross-layer tracing, and multilingual support. Designed for system developers and terminal enthusiasts.

Runs on both macOS and Linux, supporting Arm64 and Intel x86_64 architectures.

โœจ Features

Pysh

  • ๐Ÿง  Built-in commands (cd, echo, pwd, env, etc.)
  • ๐Ÿงต Multilingual support with full manuals (EN/CH/JP/KR)
  • ๐Ÿ” Cross-layer tracing: from command parsing โ†’ libc functions โ†’ C-level syscalls
  • ๐Ÿงน Composable REPL execution model
  • ๐Ÿ”Œ Pluggable command registration system

Libc

  • ๐Ÿ“จ Custom printf engine with %s, %d, %f format specifiers and escape sequences
  • ๐Ÿ“œ Native syscall bridge (Python โ†” C) via syscall/syslib.so
  • ๐Ÿงช Unit-tested via pytest, with benchmarks for key libc behaviors

๐Ÿ“ฆ Installation

Requires Python 3.10 or newer

Install via pip:

pip install shellkit

After installation, launch the interactive shell with:

pysh

๐Ÿš€ Usage

pysh [options]

CLI Options

OptionDescription
--commandRun a single command
--no-bannerSkip the startup banner
--no-reminderDisable rest reminder messages
--quietQuiet mode with minimal output
--safeEnable safety mode (blocks dangerous commands like rm -rf /)
--debugEnable shell-level debug output
--trace-echoTrace echo/printf calls down to libc syscall layer

For more, run:

pysh --help

๐Ÿ“š Examples & Tutorials

Want to see ShellKit in action? Check out our comprehensive examples:

โ†’ Examples & Demos - Real terminal sessions from basic to advanced features

Complete with multilingual demos, debugging tutorials, and advanced printf formatting!

๐Ÿ“ฆ Project Structure (partial)

shellkit/
โ”œโ”€โ”€ native/         # C code for native syscall implementation (builds syslib.so)
โ”œโ”€โ”€ shellkit/       # Main package
โ”‚   โ”œโ”€โ”€ syscall/    # Python-side syscall wrappers via ctypes
โ”‚   โ”œโ”€โ”€ libc/       # Custom libc (printf, write, exit)
โ”‚   โ”œโ”€โ”€ shell/      # Core engine, built-in commands, runtime, REPL
โ”‚   โ”œโ”€โ”€ inspector/  # Debugging and tracing tools
โ”‚   โ””โ”€โ”€ i18n/       # Multilingual dictionaries and support
โ”œโ”€โ”€ benchmarks/     # Performance benchmarks
โ”œโ”€โ”€ examples/       # Usage examples and demo logs
โ””โ”€โ”€ tests/          # Test suite

๐Ÿฅ‰ Platform Support for syslib.so

PlatformSupportedNotes
Linux x86_64โœ… YesUses rax = 1 + syscall
Linux ARM64โœ… YesUses x8 = 64 + svc #0
macOS Intel (x86)โœ… YesUses rax = 0x2000004 + syscall
macOS ARM64 (M1/M2/M3)โœ… YesUses syscall(SYS_write, ...) (soft wrapper)
WindowsโŒ NoNot supported; lacks a unified syscall() ABI

๐Ÿงญ Roadmap

ShellKit is stable and usable, but we plan to explore some exciting features in future releases:

  • ๐Ÿ”Œ Plugin System: Allow users to register custom builtin commands, aliases, and functions
  • ๐Ÿง  Deep Thinking Mode: Experimental tracing into native syscalls (e.g. eBPF or low-level syscall capture)
  • ๐Ÿงณ Persistent Profiles: Save environment variables, shell history, and custom setups
  • ๐Ÿงช More Built-ins: Extend shell with commands like ls, cat, grep
  • ๐Ÿ’ก Multiline Script Execution: Support running multi-line commands or script blocks in one go

If you're interested in any of these โ€” or have other ideas in mind โ€” feel free to open a discussion or submit a pull request.
We welcome all contributors โ€” from feature suggestions to actual code!

๐Ÿ’ฌ Turn your interest into contribution โ€” ShellKit grows better with community voices.

๐Ÿ“Œ Changelog

See CHANGELOG.md for version history.

๐Ÿ“œ License

MIT License. See LICENSE for details.

๐Ÿค Acknowledgments

Inspired by the spirit of classic Unix shells.
Thanks to all system programmers and terminal geeks who paved the way.