Skip to content

Latest commit

 

History

History
90 lines (67 loc) · 3.25 KB

ARCHITECTURE.md

File metadata and controls

90 lines (67 loc) · 3.25 KB

Architecture

This project is a small POSIX shell implementation that is intentionally Unix/Linux-focused.

High-level flow

  1. src/main.c initializes a ShellContext and loads history from $HISTFILE.
  2. shell_repl_run() (in src/repl/repl.c) drives the REPL loop:

Module map

REPL

Owns the interactive loop and glues modules together.

Line editing (raw mode)

Implements a minimal readline-like UX using termios:

  • character echo
  • backspace
  • up/down history navigation
  • tab completion integration

History

Owns:

  • in-memory history list
  • printing (with numeric indices)
  • persistence: load/save/append (including tracking the last appended index)

Completion

Owns TAB completion behavior:

  • builtin completion for the first token
  • PATH executable completion
  • bell on first ambiguous TAB, list on second TAB

Tokenizer

Tokenizes a command line in-place and implements the quote/backslash rules used by this shell.

Parser

Builds a ShellPipeline by:

  • splitting on |
  • extracting per-command redirections

Redirections

Extracts redirection tokens (>, >>, 2>, 2>>, etc.) and applies them via dup2().

Builtins

Implements builtins:

  • echo, pwd, cd, type, history, exit

Execution

Runs external programs and pipelines:

  • fork() / execv() / waitpid()
  • pipe() wiring across stages
  • builtin execution inside pipeline child processes

PATH resolution

Finds executables either directly via / paths or by searching $PATH.