init repo -
echo "# CPP-SHELL" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/Shubham-py404/CPP-SHELL.git
git push -u origin maing++ cell.cpp utils.cpp builtin.cpp -o cell && ./cellCell is a simple command-line shell implementation written in C++. It provides a basic Read-Eval-Print Loop (REPL) that reads user input, processes it, and displays output with color formatting.
cell.hpp: Header file containing includes, color definitions, and utility macroscell.cpp: Main implementation file with the shell logicutils.cppbuiltin.cpp
<iostream>: For input/output operations<unistd.h>: Providesfork()andexecvp()functions for process management (Linux systems)<sys/wait.h>: Containswait()function for process synchronization<cstdlib>: DefinesEXIT_SUCCESSconstant<vector>: For dynamic arrays (included but not used in current implementation)<string>: For string operations (included but not used in current implementation)
ANSI escape codes for terminal text coloring:
YELLOW: Yellow text colorRED: Red text colorCYAN: Cyan text colorGREEN: Green text colorRST: Reset to default color
Purpose: Reads a single line of input from the user via stdin.
Parameters: None
Behavior:
- Displays a green prompt "$$> " to indicate readiness for input
- Uses
getline()to read input from stdin - Handles EOF condition (Ctrl+D) by printing "[EOF]" in red
- Handles getline errors by printing "Getline failed" in red
- Echoes the entered text in yellow for confirmation
- Returns the buffer containing the input
Purpose: Implements the main REPL loop of the shell.
Behavior:
- Enters an infinite loop
- Calls
cell_read_line()to get user input - If input is NULL (EOF/error), breaks out of loop
- Prints the input line
- Frees the memory allocated by
getline() - Continues loop for next input
- Command parsing and execution
- Built-in commands (cd, exit, etc.)
- Command history
- Tab completion
- Cross-platform compatibility