A minimalist Unix-like shell implementation in Rust that provides core shell functionality with built-in commands.
0-Shell startup animation with ASCII art logo, welcome message, and various commands in action
0-Shell is a custom shell written in Rust that implements essential Unix shell commands as built-in functions. It features a colorized prompt, quote parsing, exit status tracking, and comprehensive error handling.
| Command | Description | Flags |
|---|---|---|
echo |
Output text to standard output | - |
cd |
Change current directory (supports ~ for home) |
- |
ls |
List directory contents | -l (long), -a (all), -F (classify) |
pwd |
Print current working directory | - |
cat |
Display file contents (supports stdin) | - |
cp |
Copy files | - |
rm |
Remove files/directories | -r (recursive) |
mv |
Move/rename files | - |
mkdir |
Create directories | - |
exit |
Exit the shell with optional status code | - |
When launching 0-Shell, an animated startup sequence displays:
- Loading animation with gradient blocks
- ASCII art logo with typewriter effect
- Colorized welcome message with author credits
- Version information and usage hints
- Displays current directory name in cyan
- Shows green arrow (
➜) for successful commands - Shows red arrow (
➜) for failed commands - Unicode wave symbol (
∿) as prefix
Example: ∿ myproject ➜
- Single quotes (
'...'): Literal string, no escape processing - Double quotes (
"..."): Supports escape sequences - Escape sequences in double quotes:
\n,\t,\\,\"
- Tracks last command exit status
- Access via
echo $? - Exit codes follow Unix conventions:
0: Success1: General errors127: Command not found
Ctrl+Dexits the shell gracefully
The ls implementation provides Unix-like directory listing with:
-lflag: Long format showing permissions, links, owner, group, size, modification time-aflag: Show hidden files (including.and..)-Fflag: Append indicators (/for directories,*for executables,@for symlinks,|for FIFOs,=for sockets)- Symlink resolution and target display
- Extended attributes detection (
+indicator) - Device file major/minor number display
- Proper column alignment
- Removes files by default
-rflag: Recursive deletion for directories- Error handling for non-existent files
- Changes to specified directory
cdorcd ~: Changes to home directory- Handles permission and access errors
- Displays file contents
- Reads from stdin if no file specified (until EOF)
- Handles multiple files
- Copies single file to destination
- Copies multiple files to directory
- Detects same-file copy attempts
- Handles file/directory collisions
- Moves/renames files and directories
- Supports multiple source files to directory
- Detects same-file move attempts
0-shell/
├── Cargo.toml # Project configuration and dependencies
└── src/
├── main.rs # Entry point, main loop, prompt handling
├── init.rs # Command parsing with quote handling
├── execute.rs # Command dispatcher
└── builtins/
├── mod.rs # Module exports
├── cat.rs # cat command implementation
├── cd.rs # cd command implementation
├── cp.rs # cp command implementation
├── echo.rs # echo command implementation
├── exit.rs # exit command implementation
├── ls.rs # ls command implementation
├── mkdir.rs # mkdir command implementation
├── mv.rs # mv command implementation
├── pwd.rs # pwd command implementation
└── rm.rs # rm command implementation
| Crate | Version | Purpose |
|---|---|---|
chrono |
0.4.41 | Date/time formatting for ls -l |
colored_text |
0.3.0 | Colorized terminal output |
dirs-next |
2.0.0 | Home directory detection |
libc |
0.2.174 | Low-level system calls (extended attributes) |
users |
0.11.0 | User/group name resolution |
zeroize |
1.8.1 | Secure memory clearing |
- Rust toolchain (rustc, cargo)
- Linux/Unix environment
# Debug build
cargo build
# Release build (optimized)
cargo build --release# After debug build
./target/debug/shell
# After release build
./target/release/shell# Navigate directories
cd /tmp
cd ~
pwd
# List files
ls
ls -la
ls -lF /home
# File operations
echo "Hello World"
cat file.txt
cp source.txt dest.txt
mv old.txt new.txt
mkdir mydir
rm file.txt
rm -r directory/
# Exit status
echo $?
exit 0
exit 1| Feature | Status | Notes |
|---|---|---|
| Display prompt and await input | ✅ | Custom colorized prompt |
| Parse and execute commands | ✅ | Full command parsing with quotes |
| Return to prompt after completion | ✅ | Main loop implementation |
| Exit on Ctrl+D (EOF) | ✅ | Handled in main loop |
echo command |
✅ | Fully implemented |
cd command |
✅ | With home directory support |
ls command |
✅ | With -l, -a, -F flags |
pwd command |
✅ | With fallback for deleted directories |
cat command |
✅ | With stdin support |
cp command |
✅ | Single and multi-file support |
rm command |
✅ | With -r recursive flag |
mv command |
✅ | With multi-file support |
mkdir command |
✅ | Fully implemented |
exit command |
✅ | With exit code support |
| Error message for unknown commands | ✅ | "command not found" message |
| Constraint | Status | Notes |
|---|---|---|
| No external binary spawning | Falls back to external commands for non-builtins | |
| No globbing | ✅ | Not implemented |
| No redirection | ✅ | Not implemented |
| Unix-like behavior | ✅ | Follows Unix conventions |
| Feature | Status | Notes |
|---|---|---|
| Startup animation | ✅ | Animated logo and welcome message |
| Ctrl+C handling | ❌ | Not implemented |
| Auto-completion | ❌ | Not implemented |
| Command history | ❌ | Not implemented |
| Current directory in prompt | ✅ | Shows last path component |
| Colorized output | ✅ | Prompt and startup use colors |
Command chaining (;) |
❌ | Not implemented |
Pipes (|) |
❌ | Not implemented |
I/O redirection (>, <) |
❌ | Not implemented |
| Environment variables | Only $? supported |
|
Custom help command |
❌ | Not implemented |
-
External Command Fallback: When a command is not a built-in, the shell attempts to execute it as an external binary using
std::process::Command. This may violate the "no external binary spawning" constraint. -
Cargo.toml Edition: Uses
edition = "2024"which is a future edition. Should beedition = "2021"for current stable Rust. -
Echo Trailing Space: The
echocommand adds a trailing space after each argument. -
No SIGINT Handling: Ctrl+C is not handled and may terminate the shell.
- Uses
zeroizecrate for secure memory clearing of sensitive input - Input strings are zeroized after use to prevent memory leaks of sensitive data
- Comprehensive error messages for all file operations
- Graceful handling of permission denied, file not found, and other I/O errors
- Error messages follow Unix conventions
- Modular design with separate files for each built-in command
- Extensive documentation comments
- Proper use of Rust idioms (Result types, pattern matching)
- Test all built-in commands with various arguments
- Verify
ls -loutput format matches Unixls - Test quote handling with nested and escaped quotes
- Verify error messages for invalid operations
- Test
cdwith relative and absolute paths - Verify
rm -rworks correctly on nested directories - Test
cpandmvwith multiple files - Verify exit status tracking with
echo $?
- Implement SIGINT (Ctrl+C) handling
- Add command history with arrow key navigation
- Implement tab auto-completion
- Add pipe (
|) and redirection (>,<) support - Add command chaining with
; - Implement more environment variable support
- Add
helpcommand with usage information - Remove external command fallback to comply with constraints
This project is part of the Zone01 curriculum and is intended for educational purposes.
Developed as part of the 0-shell project at Zone01 Oujda.
- Hamza Boutaleb - GitHub
- Khalid El Amrani - Co-developer
