Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Custom Shell Implementation

Author: Hardik Chadha

A feature-rich shell implementation in C with custom built-in commands and full support for system commands, background processes, and command history.

Table of Contents

Installation

  1. Clone/Download the project to your local machine

  2. Navigate to the project directory

  3. Compile the shell:

    make
  4. Run the shell:

    ./a.out

General Information

  • Maximum background processes: 100 concurrent processes
  • Maximum input size: 1023 characters
  • Maximum path length: 4095 characters
  • Command chaining: Supports multiple commands separated by ;
  • Background execution: Supports & for background processes
  • Signal handling: Automatic cleanup of terminated background processes

Built-in Commands

1. hop / cd - Directory Navigation

Changes the current working directory with enhanced path support.

Syntax:

hop [path1] [path2] ... [pathN]
cd [path1] [path2] ... [pathN]

Special Path Shortcuts:

  • ~ - Home directory
  • . - Current directory
  • .. - Parent directory
  • - - Previous directory

Examples:

hop ~                    # Go to home directory
hop ..                   # Go to parent directory
hop -                    # Go to previous directory
hop ~/Documents          # Go to Documents folder in home
hop /usr/local/bin       # Absolute path navigation
hop dir1 dir2 dir3       # Navigate through multiple directories sequentially

Features:

  • Supports multiple path arguments (navigates to each sequentially)
  • Remembers previous directory for - navigation
  • Prints the full path after each directory change
  • Error handling for invalid paths

2. reveal - Enhanced File Listing

Advanced file listing command with multiple display options and color-coded output.

Syntax:

reveal [options] [path]

Options:

  • -a : Show hidden files (files starting with .)
  • -l : Long format (detailed information)
  • -al or -la : Combine both options

Color Coding:

  • Blue: Directories
  • Green: Executable files
  • White: Regular files

Examples:

reveal                   # List files in current directory
reveal -a               # Show all files including hidden ones
reveal -l               # Detailed listing with permissions, size, date
reveal -al ~/Documents  # Detailed listing of all files in Documents
reveal /usr/bin         # List files in /usr/bin directory

Long Format Information:

  • File permissions (rwxrwxrwx)
  • Number of hard links
  • Owner username
  • Group name
  • File size in bytes
  • Last modification time
  • File/directory name (color-coded)

3. log - Command History Management

Manages command history with execution, viewing, and purging capabilities.

Syntax:

log                      # Display command history
log purge               # Clear all command history
log execute <number>    # Execute command from history

Examples:

log                     # Show last 15 commands
log execute 3           # Execute the 3rd most recent command
log purge              # Delete entire command history

Features:

  • Automatically stores up to 15 most recent commands
  • Prevents duplicate consecutive commands
  • Commands are numbered from most recent (1) to oldest (15)
  • Persistent storage across shell sessions
  • Automatic overflow management (removes oldest when limit exceeded)

4. proclore - Process Information

Displays detailed information about running processes.

Syntax:

proclore [pid]

Examples:

proclore                # Show info about current shell process
proclore 1234          # Show info about process with PID 1234

Information Displayed:

  • Process ID (PID): Unique process identifier
  • Process Status: Current state (R=Running, S=Sleeping, Z=Zombie, etc.)
  • Process Group: Process group identifier
  • Virtual Memory: Memory usage in pages
  • Executable Path: Full path to the executable file

5. seek - Advanced File/Directory Search

Powerful search tool with filtering and execution capabilities.

Syntax:

seek [options] <target> [search_directory]

Options:

  • -d : Search only directories
  • -f : Search only files
  • -e : Execute/open found item if exactly one match

Examples:

seek main.c             # Search for main.c in current directory
seek -d Documents       # Search for directories named "Documents"
seek -f "*.txt" ~       # Search for txt files in home directory
seek -e config.conf     # Search and open config.conf if unique match
seek -df backup /usr    # Search for directories named "backup" in /usr

Color Coding:

  • Blue: Directories
  • Green: Files

Execute Feature (-e flag):

  • If exactly one match found:
    • Directory: Changes to that directory
    • File: Displays file contents
  • Multiple matches: Just lists them (no execution)
  • No matches: Shows "No match found!"
  • Handles permission errors gracefully

6. System Commands

All standard system commands are supported and can be executed normally.

Examples:

ls -la                  # Standard ls command
grep "pattern" file.txt # Text search with grep
ps aux                  # Process listing
vim file.txt           # Open file in vim
gcc -o program main.c  # Compile C program

Features

Background Process Management

Run commands in the background using the & operator.

Examples:

sleep 10 &              # Run sleep in background
gedit file.txt &        # Open text editor in background
./long_running_task &   # Execute program in background

Background Process Features:

  • Automatic notification when background processes complete
  • Tracks process names and PIDs
  • Handles up to 100 concurrent background processes
  • Shows exit status and termination signals
  • Automatic cleanup of zombie processes

Command Chaining

Execute multiple commands in sequence using ; separator.

Examples:

hop ~/Documents; reveal -la; log  # Chain multiple commands
cd ..; ls; pwd                    # Navigate, list, show path

Foreground Process Timing

Automatically tracks and displays execution time for long-running foreground processes (>2 seconds).

Display Format:

<username@hostname:path command_name : time_in_seconds>

Advanced Prompt

The shell provides a colorful, informative prompt showing:

  • Username (orange color)
  • Hostname (blue color)
  • Current directory (with ~ substitution for home)
  • Execution time for long-running commands

Path Handling

Smart path resolution supporting:

  • Absolute paths: /usr/local/bin
  • Relative paths: ../parent/directory
  • Home directory: ~/Documents
  • Previous directory: -
  • Current directory: .

Error Handling

Comprehensive error handling for:

  • Invalid commands and arguments
  • Permission denied scenarios
  • File/directory not found cases
  • Process execution failures
  • Signal handling for interrupted processes

Exit Commands

Exit the shell using any of these commands:

  • exit
  • quit
  • q

Usage Examples

Basic Navigation and File Operations

# Navigate to home and list files
hop ~
reveal -la

# Search for C files and view one
seek -f "*.c"
seek -e main.c

# Check command history
log
log execute 2

Process Management

# Run background process and check its info
sleep 30 &
proclore 1234

# Chain commands with timing
time sleep 3; echo "Done"

Advanced File Operations

# Search in specific directory with filters
seek -d "build" ~/projects
seek -f config /etc

# Detailed file listing with history
reveal -al /var/log; log

This shell provides a rich command-line experience with powerful built-in utilities while maintaining full compatibility with standard system commands.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages