Overview

The FreeWorld Shell is a console application that provides a text-based interface for running commands, scripts, and interacting with the file system. It features modern capabilities like long file name support and advanced scripting.

Status: ✅ All shell enhancements fully implemented
Complete shell with command history, tab completion, scripting, aliases, functions, variables, job control, redirection, pipes, conditionals, and loops. Total: ~2,900 lines of code.

Shell Enhancements

FreeWorld Shell includes comprehensive enhancements for modern shell usage:

Command History

  • History Navigation: Arrow keys (↑/↓) to navigate command history
  • History Storage: Persistent command history storage
  • History Search: Search through command history
  • Location: shell/history.c (~320 lines)

Tab Completion

  • Command Completion: Tab completion for commands
  • File Completion: Tab completion for file paths
  • Completion Display: Shows available completions
  • Location: shell/completion.c (~300 lines)

Shell Scripting

  • Script Execution: Execute shell scripts from files
  • Conditionals: if/else and case statements
  • Loops: for, while, until loops
  • Location: shell/scripting.c (~600 lines)

Shell Aliases

  • Command Aliases: Create command aliases
  • Alias Management: List, create, remove aliases
  • Location: shell/aliases.c (~200 lines)

Shell Functions

  • Function Definition: Define shell functions
  • Function Execution: Execute defined functions
  • Location: shell/functions.c (~300 lines)

Shell Variables

  • Environment Variables: Access and modify environment variables
  • Shell Variables: Local shell variables
  • Variable Expansion: Expand variables in commands
  • Location: shell/variables.c (~400 lines)

Shell Job Control

  • Background Jobs: Run commands in background
  • Job Management: List, foreground, background jobs
  • Job Control: Control job execution
  • Location: shell/job_control.c (~400 lines)

Shell Redirection

  • Output Redirection: > (overwrite), >> (append)
  • Input Redirection: < (input from file), << (here document)
  • Location: shell/redirection.c (~300 lines)

Shell Pipes

  • Command Piping: Pipe output of one command to input of another
  • Multiple Pipes: Chain multiple commands with pipes
  • Location: shell/pipes.c (~200 lines)

Shell Conditionals

  • if/else: Conditional execution based on command exit status
  • case: Multi-way conditional based on pattern matching
  • Location: shell/scripting.c (included in scripting)

Shell Loops

  • for: Iterate over lists
  • while: Loop while condition is true
  • until: Loop until condition is true
  • Location: shell/scripting.c (included in scripting)
Status: ✅ All shell enhancements fully implemented (~2,900 lines total)

Prompt Design

The shell displays a distinctive prompt:

FREE WORLD>

Where "FREE" is displayed in blue and "WORLD" is displayed in white.

ANSI Color Codes

#define COLOR_BLUE "\033[34m"
#define COLOR_WHITE "\033[37m"
#define COLOR_RESET "\033[0m"

Constants

Constant Value Description
MAX_INPUT 1024 Maximum input line length
MAX_ARGS 64 Maximum number of command arguments
COLOR_BLUE "\033[34m" ANSI blue color code
COLOR_WHITE "\033[37m" ANSI white color code
COLOR_RESET "\033[0m" ANSI reset color code

Functions

print_prompt

Displays the shell prompt with colored text:

void print_prompt(void);

print_welcome

Displays welcome message on shell startup:

void print_welcome(void);

execute_command

Executes a shell command:

int execute_command(char** args, int argc);

Returns: 0 on success, -1 to exit, 1 on error

parse_input

Parses input string into command arguments:

int parse_input(char* input, char** args, int max_args);

Built-in Commands

The shell includes a comprehensive set of commands compatible with Windows CMD and Unix shells. Commands are case-insensitive and support both Windows-style (/option) and Unix-style (-option) flags.

File and Directory Commands

Command Description Usage Options
DIR, LS List directory contents dir [dir] [options] /W (wide), /P (paged), /A (all), /B (bare), /H (human-readable)
CD, CHDIR Change directory cd [dir] -
PWD Print working directory pwd -
MKDIR, MD Create directory mkdir <dir> -
RMDIR, RD Remove directory rmdir <dir> -
TOUCH Create empty file touch <file> -
RM, DEL, ERASE Remove file rm <file> -
CAT, TYPE Display file contents cat <file> -
COPY Copy file copy <src> <dst> -
MOVE, REN, RENAME Move/rename file move <src> <dst> -
TREE Display directory tree tree [dir] -
FIND, FINDSTR Search for text in files find <pattern> [file] -

System Commands

Command Description Usage
HELP Show help message help [command]
EXIT, QUIT Exit the shell exit
ECHO Echo text echo [text]
CLEAR, CLS Clear screen clear
DATE Display/set date date [date]
TIME Display/set time time [time]
VER Display version ver
VOL Display volume label vol
SYSTEMINFO Display system information systeminfo
FWMIC FreeWorld Management Instrumentation and Control fwmic [options] [query]
DIR/LS Command Features:
  • ✅ Optimized directory listing with qsort (O(n log n))
  • ✅ Multiple display formats (/W wide, /P paged, /B bare)
  • ✅ Human-readable file sizes (/H option)
  • ✅ Color-coded output (directories in green, files in white)
  • ✅ File attributes display (D=Directory, R=Read-only, etc.)
  • ✅ Sorted output (directories first, then alphabetical)

Command History

The shell includes a command history system with arrow key navigation:

  • Up Arrow: Navigate to previous command
  • Down Arrow: Navigate to next command
  • History Buffer: Stores up to 100 commands
  • Raw Mode Input: Character-by-character input on Unix-like systems
  • Fallback Mode: Simple fgets-based input on Windows/WSL

Location: shell/history.c, shell/history.h

Status: ✅ Complete - Works on Unix-like systems, fallback on Windows

FWMIC (FreeWorld Management Instrumentation and Control)

FWMIC is a WMI-like system for accessing management data from the operating system, hardware, and applications. It provides:

  • Hardware Inventory: Computer system, processor, memory, disk information
  • Software Inventory: OS version, BIOS information
  • Query Engine: WQL-like query language
  • Provider System: Extensible provider architecture

Location: shell/fwmic.c, shell/fwmic.h

Status: ✅ Complete - Basic providers implemented

Usage Examples

fwmic /query "SELECT * FROM OS"
fwmic /query "SELECT Name FROM ComputerSystem"
fwmic /query "SELECT * FROM Processor"

Cross-Platform Support

The shell supports both Windows and Linux:

#ifdef _WIN32
#include 
#include 
#define access _access
#define stat _stat
#else
#include 
#include 
#endif

Main Loop

The shell runs a continuous loop:

  1. Display prompt
  2. Read user input
  3. Parse input into arguments
  4. Execute command
  5. Repeat until exit command