Dose - DOS-Style Command Shell
Dose is a DOS-style command shell implementation written in Zig. Originally started in Rust, the project has been completely rewritten in Zig to provide a nostalgic DOS computing experience with modern systems programming capabilities.
This project faithfully reproduces classic MS-DOS command behaviors, syntax, and error messages while running on modern systems.
Features
Interactive REPL Shell
- DOS-style command prompt (
C:\PATH>) - Complete lexer/parser for DOS command syntax with quote support
- Authentic DOS behavior and error messages
Built-in Commands
Core File Operations:
- COPY - File copying with overwrite prompts and device handling
- DIR - Directory listing with file sizes, counts, and free space display
- TYPE - Display file contents with binary character filtering
- CD/CHDIR - Directory navigation with path validation
Extended File Operations:
- MD/MKDIR - Directory creation with nested path support
- RD/RMDIR - Directory removal with safety checks
- REN/RENAME - File and directory renaming
- DEL/REMOVE - File deletion with wildcard support
- PATH - Environment PATH variable management (GET/SET)
- MOVE - File/directory moving (placeholder)
Shell and System Commands:
- ECHO (with ON/OFF variants) - Text output and echo state control
- CLS - Clear screen with ANSI escape sequences
- EXIT - Exit the shell
- VER - Version information display
- DATE - Current system date with proper calendar calculations
- TIME - Current system time display
- SORT - Alphabetical line sorting with input redirection support
I/O Redirection System
- Input redirection (
<): Read file content as command input - Output redirection (
>): Write command output to file (overwrite) - Append redirection (
>>): Append command output to file - Combined redirection: Support for both input and output redirection simultaneously
- Device handling: Proper CON/LPT/PRN device recognition and error handling
External Command Support
- Full process spawning with I/O redirection support
- Proper command-line argument handling
- DOS-compatible "command not found" messages
- Exit code propagation
Path Formatting
- DOS-style path display with drive letters
- 8.3 filename conversion where applicable
- Converts
/to\and uppercases drive letters and names - Defaults to
C:when no drive is present
Technical Features
Memory Management
- Allocator-based: Uses Zig's
GeneralPurposeAllocatorfor all dynamic memory - RAII Pattern: Proper resource cleanup with
deferstatements - Leak Detection: Built-in memory leak detection in debug builds
Error Handling
- Zig Error Unions: Native
!Terror handling instead of exceptions - DOS-Authentic Messages: Faithful reproduction of classic DOS error text
- Graceful Degradation: Robust error recovery and user guidance
Architecture
- Type-Safe Commands: Uses Zig unions and enums for command architecture
- Modular Design: Clean separation between parsing, execution, and I/O
- Zero Dependencies: Uses only Zig standard library
- Cross-Platform: Portable file system and process operations
Build
Requirements: - Zig (recent version)
Commands:
# Development
zig build # Build debug version
zig build run # Build and run in debug mode
zig build test # Run unit tests
zig build -Doptimize=ReleaseFast # Optimized build
This produces an executable in zig-out/bin/dose.
Run
Start the shell:
zig-out/bin/dose
You’ll see a DOS-like prompt. Example interactions:
C:\> VER
DOSE Version 6.22
C:\> DIR
... directory listing ...
C:\> COPY CON hello.txt
Hello world!
^Z
1 File(s) copied
C:\> TYPE hello.txt
Hello world!
Redirection:
C:\> DIR > dir.txt
C:\> TYPE dir.txt
Change directory:
C:\> CD ..
C:\> DIR
Project Structure
src/
├── cmd/ # Modular command implementations
│ ├── lib/
│ │ └── types.zig # Shared command types and interfaces
│ ├── chdir.zig # CD/CHDIR command
│ ├── cls.zig # CLS command
│ ├── copy.zig # COPY command
│ ├── date.zig # DATE command
│ ├── dir.zig # DIR command
│ ├── echo.zig # ECHO command variants
│ ├── mkdir.zig # MD/MKDIR command
│ ├── move.zig # MOVE command (placeholder)
│ ├── path.zig # PATH command (GET/SET)
│ ├── remove.zig # DEL/REMOVE command
│ ├── rename.zig # REN/RENAME command
│ ├── rmdir.zig # RD/RMDIR command
│ ├── sort.zig # SORT command
│ ├── time.zig # TIME command
│ └── type.zig # TYPE command
├── cmd.zig # Command type definitions and imports
├── eval.zig # Command execution engine
├── parser.zig # DOS command line parser
├── paths.zig # DOS path formatting utilities
├── syntax.zig # Command syntax structures
└── main.zig # Application entry point and REPL
License
GNU AGPLv3.
