explaingit

johndcode/st3sh2

11MakefileAudience · developerComplexity · 4/5ActiveSetup · moderate

TLDR

A hand-written POSIX-compliant Unix shell in C paired with a threaded pseudo-terminal layer, with full list operators, pipelines, and redirections.

Mindmap

mindmap
  root((st3sh2))
    Inputs
      User commands
      Pipes and redirects
      PTY master/slave
    Outputs
      Command exit codes
      Pipeline output
      Terminal IO
    Use Cases
      Learn shell internals
      Study PTY threading
      Embed a mini shell
    Tech Stack
      C
      Makefile
      POSIX
      pthreads

Things people build with this

USE CASE 1

Read a from-scratch POSIX shell lexer, parser, and executor

USE CASE 2

Study a threaded PTY layer that avoids blocking on terminal IO

USE CASE 3

Run pipelines and POSIX list operators on a small custom shell

USE CASE 4

Adapt the PTY module into another C application that drives terminals

Tech stack

CMakefilePOSIXpthreads

Getting it running

Difficulty · moderate Time to first run · 30min

Hand-written C with a Makefile, so you need a Unix toolchain and pthreads to build.

In plain English

st3sh2 is a personal project that bundles two related pieces of low-level Unix software, both written by hand in C. The author notes at the top of the README that none of the code was generated by AI, although the README itself was written by an AI for fun. The repository is the second iteration of an earlier project called st3sh. The first piece is the shell itself, also called st3sh2. The author describes it as POSIX-compliant, meaning it follows the same command language standard that bash and other Unix shells follow. It has a hand-written lexer and parser, so the user input is first turned into tokens, then grouped, and then resolved into a clean command tree before anything runs. Simple commands, compound commands, and chains joined by separators all go through the same execution path. On the feature side, the shell supports the three POSIX command list operators: semicolon for sequential runs, double ampersand for run-on-success, and double pipe for run-on-failure. Pipelines connect the standard output of one command to the standard input of the next using kernel pipes, with a forked child process per stage and the exit status of the last command in the chain becoming the pipeline's exit status. Pipelines can be nested to any depth. The full set of POSIX redirections is supported, covering output truncation and append, input from a file, stderr redirects, swaps between stdout and stderr, and arbitrary file-descriptor redirects. There are also built-in commands that have to run inside the shell process, with a help command listing them, and the usual POSIX quoting rules and word expansions. The second piece is the pseudo-terminal layer underneath, kept in a directory called pty. It manages master and slave terminal pairs and uses background threads instead of a single select or poll loop in the main thread. A reader thread streams data out of the PTY master, a writer thread drains a write queue, and thread-safe queues with condition variables coordinate them. The README says this means the calling application never blocks on terminal input or output. The author points at a POSIX.1-2017 specification link as the target for the shell and notes that a to-do list inside the repo tracks the features that are not finished yet.

Copy-paste prompts

Prompt 1
Walk me through how st3sh2 turns input into a command tree before execution
Prompt 2
Show me how the pipeline stages fork and connect with kernel pipes
Prompt 3
Help me understand the reader and writer threads in the pty directory
Prompt 4
Explain which POSIX redirections st3sh2 supports and where they are parsed
Prompt 5
Generate a test script that exercises the && and || list operators
Open on GitHub → Explain another repo

Generated 2026-05-22 · Model: sonnet-4-6 · Verify against the repo before relying on details.