Skip to content

Omar123098/Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

14 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Windows Shell Implementation

A featured, Windows-compatible shell with advanced interactive capabilities, tab completion, command history, and comprehensive I/O redirection support.

Built from scratch in C++ using native Windows APIs for optimal performance and user experience.

๐Ÿš€ Key Features

Advanced Interactive Shell

  • Custom Readline Implementation: Built from scratch using Windows APIs (_getch()) for immediate key response
  • Full Cursor Navigation: Move cursor freely within command line using arrow keys
  • Advanced Line Editing: Insert, delete, and modify text at any cursor position
  • Persistent Command History: Commands saved to history.txt and restored between sessions

Intelligent Tab Completion System

  • Command Completion: Auto-complete built-in commands and executables in PATH
  • File/Directory Completion: Complete filenames and directory names in current directory
  • Smart Completion Logic:
    • Single match: Automatically completes
    • Multiple matches: Double-tab shows all options
    • No matches: System beep notification
  • Context-Aware: Completes commands at start of line, files/directories elsewhere

Enhanced Navigation & History

  • Arrow Key Navigation:
    • โ†‘/โ†“: Navigate through command history
    • โ†/โ†’: Move cursor within current line
  • Advanced History Features:
    • history: Show all commands with line numbers
    • history n: Show last n commands
    • History persistence across sessions
    • Smart history backup during navigation

Comprehensive Built-in Commands

Command Description Advanced Features
echo <text> Print text to output Quote parsing, escape sequences, I/O redirection
pwd Print working directory Windows path format support
cd <path> Change directory Home directory (~) support via USERPROFILE
ls [path] List directory contents Hidden file filtering, I/O redirection
cat <file> Display file contents Error handling, I/O redirection
type <cmd> Show command information Built-in vs external command detection
history [n] Show command history Optional line count, persistent storage
exit [0] Exit shell Clean shutdown

Advanced I/O Redirection

  • Output Redirection: >, >>, 1>, 1>>
  • Intelligent Parsing: Handles redirection within echo commands
  • File Operations: Create, overwrite, and append to files
  • Error Handling: Graceful handling of file access errors

Windows-Specific Optimizations

  • Path Handling: Windows backslash separators and drive letters
  • Environment Variables: USERPROFILE for home directory, PATH for executables
  • Console APIs: Native Windows console functions for optimal performance
  • File Extensions: Automatic .exe extension handling for executables

๐ŸŽฎ Key Bindings

Key Action
Enter Execute command
Tab Auto-complete command/filename
Tab Tab Show all completion options
โ†‘ Previous command in history
โ†“ Next command in history
โ† Move cursor left
โ†’ Move cursor right
Backspace Delete character before cursor
Delete Delete character after cursor
Ctrl+D Exit shell

๐Ÿ› ๏ธ Local Installation Guide

Prerequisites

Before installing the project locally, ensure you have the following:

  • Windows 10/11 (64-bit recommended)
  • MinGW-w64 or Microsoft Visual Studio (with C++ compiler)
  • Git (for cloning the repository)
  • PowerShell or Command Prompt

Installation Methods

Method 1: Quick Installation (Recommended)

# 1. Clone the repository to your local machine
git clone https://github.com/Omar123098/Shell
cd "Shell project"

# 2. Compile the project
g++ main.cpp -o shell.exe

# 3. Run the shell immediately
.\shell.exe

Method 2: Development Setup

# 1. Clone and navigate to project
git clone https://github.com/Omar123098/Shell
cd "Shell project"

# 2. Create build directory for organized compilation
mkdir build -Force
cd build

# 3. Compile with optimizations
g++ -O2 -std=c++17 ..\main.cpp -o shell.exe

# 4. Test the installation
.\shell.exe

Method 3: System-Wide Installation

# 1. Follow Method 1 or 2 to compile
# 2. Copy to a directory in your PATH (requires admin privileges)
copy shell.exe "C:\Program Files\CustomShell\shell.exe"

# 3. Add to PATH environment variable
# Go to System Properties > Environment Variables
# Add "C:\Program Files\CustomShell" to PATH

# 4. Now you can run from anywhere
shell.exe

Verifying Installation

After installation, verify everything works correctly:

# Test basic functionality
.\shell.exe

# In the shell, try these commands:
$ pwd                    # Should show current directory
$ echo "Hello World"     # Should print "Hello World"
$ history               # Should show command history
$ ls                    # Should list directory contents
$ exit                  # Should close the shell

Troubleshooting

Common Issues:

  1. Compiler not found: Install MinGW-w64 or Visual Studio Build Tools
  2. Permission denied: Run PowerShell as Administrator for system-wide installation
  3. File not found: Ensure you're in the correct directory (Shell project)
  4. Compilation errors: Check that you have C++17 support

Quick Fixes:

# Check if g++ is available
g++ --version

# Install MinGW-w64 via chocolatey (if you have it)
choco install mingw

# Or download from: https://www.mingw-w64.org/downloads/

๐Ÿ“– Usage Examples

Basic Commands

$ pwd
C:\Users\YourName\shell-cpp\src

$ echo "Hello, World!"
Hello, World!

$ ls
main.cpp  shell.exe  history.txt

Tab Completion

$ ec<TAB>        # Completes to "echo"
$ ls ma<TAB>     # Completes to "main.cpp"
$ his<TAB><TAB>  # Shows "history" if available

Command History

$ history        # Show all commands
1. pwd
2. echo "Hello"
3. ls

$ history 2      # Show last 2 commands
2. echo "Hello"
3. ls

I/O Redirection

$ echo "Hello" > output.txt          # Write to file
$ echo "World" >> output.txt         # Append to file
$ ls > filelist.txt                  # Save directory listing
$ cat output.txt
Hello
World

Advanced Line Editing

$ echo "This is a test"
# Use โ† โ†’ arrows to move cursor
# Use Backspace/Delete to edit anywhere in line
# Use โ†‘ โ†“ to navigate history while editing

๐Ÿ—๏ธ Architecture

Core Components

  1. readline() - Custom input handler with advanced editing
  2. find_completion() - Tab completion system
  3. Command Processors - Individual handlers for each built-in command
  4. History Manager - Persistent command history with file I/O
  5. I/O Redirector - Output redirection parsing and handling

Key Technical Features

  • Memory Management: Proper allocation/deallocation of dynamic strings
  • Error Handling: Comprehensive error checking for file operations
  • Windows Integration: Native Windows API usage for optimal performance
  • Cross-Platform Considerations: Easy adaptation to Unix systems if needed

๐Ÿงช Testing

The shell has been thoroughly tested with:

  • โœ… All basic shell operations
  • โœ… Complex command line editing scenarios
  • โœ… Tab completion edge cases
  • โœ… I/O redirection combinations
  • โœ… History navigation with cursor movement
  • โœ… Error conditions and recovery

๐Ÿš€ Deployment

Building Release Version

g++ -O2 -DNDEBUG main.cpp -o shell.exe

Installation

# Copy to a directory in your PATH
copy shell.exe C:\Windows\System32\myshell.exe

๐Ÿ”ง Customization

Adding New Commands

  1. Add command name to commands vector
  2. Implement command handler function
  3. Add handler call in main command processing loop
  4. Update help documentation

Modifying Key Bindings

Edit the key code handling in readline() function:

else if (ch == YOUR_KEY_CODE) {
    // Your custom key handling
}

๐Ÿ“ License

This project is open source and available for educational and commercial use. Feel free to use, modify, and distribute.

๐Ÿ”ฎ Future Updates

Upcoming Features

  1. Piping Support - Full pipe implementation (command1 | command2)
  2. Background Processes - Job control with &, jobs, fg, bg commands
  3. Enhanced Commands - Add mkdir, cp, mv, rm, find commands
  4. CI/CD Pipeline - Automated testing and release workflow via GitHub Actions

๐Ÿค Contributing

Contributions are welcome! Key areas for enhancement:

  • Additional built-in commands
  • More sophisticated I/O redirection
  • Cross-platform compatibility improvements
  • Performance optimizations

๐Ÿ† Features Showcase

This implementation demonstrates C++ programming techniques:

  • Custom readline implementation
  • Windows API integration
  • Sophisticated command parsing
  • Memory management best practices
  • Professional code documentation

Video

Watch the video

About

A Windows-compatible shell built in C++ featuring custom readline, command history, tab completion, built-in commands (echo, ls, cd, etc.), and I/O redirection. It demonstrates Windows API usage, modern C++ techniques, and core shell concepts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages