Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Muski Shell

A lightweight, custom shell implementation in C with essential command-line utilities. Built from scratch to understand how shells work at a low level using system calls and process management.

๐Ÿš€ Features

Built-in Commands

  • cd [directory] - Change directory with home directory support (cd ~)
  • exit - Exit the shell gracefully

External Commands

  • echo [text] - Print text to standard output
  • ls [directory] - List files and directories with color coding
    • ๐Ÿ”ต Blue for directories
    • ๐ŸŸข Green for files
  • clear - Clear the terminal screen
  • touch [filename] - Create empty files
  • edit [filename] - Simple text editor with save/quit functionality

Core Shell Features

  • Real-time current working directory display
  • Command parsing and tokenization
  • Process management with fork() and execv()
  • Error handling for invalid commands and system calls
  • Custom prompt: Muski-shell: /current/path>

๐Ÿ“ฆ Build Instructions

Prerequisites

  • GCC compiler
  • Linux/Unix environment
  • Standard C library

Compilation Steps

  1. Clone or navigate to the project directory:

    cd /path/to/Muski-shell
  2. Create the build directory:

    mkdir -p build
  3. Compile all command utilities:

    gcc commands/echo.c -o build/echo
    gcc commands/ls.c -o build/ls
    gcc commands/clear.c -o build/clear
    gcc commands/touch.c -o build/touch
    gcc commands/edit.c -o build/edit
  4. Compile the main shell:

    gcc main.c -o terminal
  5. Run the shell:

    ./terminal

Quick Build Script

Create a build.sh file for easier compilation:

#!/bin/bash
mkdir -p build
gcc commands/echo.c -o build/echo
gcc commands/ls.c -o build/ls
gcc commands/clear.c -o build/clear
gcc commands/touch.c -o build/touch
gcc commands/edit.c -o build/edit
gcc main.c -o terminal
echo "Build complete! Run ./terminal to start."

Then run: chmod +x build.sh && ./build.sh

๐Ÿ“– Command Reference

Basic Commands

# Display text
echo Hello, World!

# List files in current directory
ls

# List files in specific directory
ls /home/user

# Change directory
cd /path/to/directory
cd ~  # Go to home directory
cd .. # Go to parent directory

# Create empty file
touch myfile.txt

# Clear screen
clear

# Exit shell
exit

Text Editor (edit)

# Open or create a file
edit myfile.txt

# Editor commands:
:w      # Save file
:q      # Quit without saving
:wq     # Save and quit
:l      # List all lines with numbers
:d5     # Delete line 5

๐Ÿ“‚ Project Structure

Muski-shell/
โ”œโ”€โ”€ main.c              # Main shell loop and built-in commands
โ”œโ”€โ”€ commands/           # External command implementations
โ”‚   โ”œโ”€โ”€ echo.c         # Echo command
โ”‚   โ”œโ”€โ”€ ls.c           # List files with colors
โ”‚   โ”œโ”€โ”€ clear.c        # Clear terminal
โ”‚   โ”œโ”€โ”€ touch.c        # Create files
โ”‚   โ””โ”€โ”€ edit.c         # Simple text editor
โ”œโ”€โ”€ build/             # Compiled binaries (gitignored)
โ”œโ”€โ”€ terminal           # Main shell executable (gitignored)
โ”œโ”€โ”€ .gitignore         # Git ignore rules
โ””โ”€โ”€ README.md          # This file

๐Ÿ’ก Usage Examples

Example Session

Muski-shell: /home/user/projects>
ls
file1.txt    folder1    script.sh    README.md

Muski-shell: /home/user/projects>
echo Creating a new file...
Creating a new file...

Muski-shell: /home/user/projects>
touch notes.txt

Muski-shell: /home/user/projects>
edit notes.txt
=== Simple Text Editor ===
edit> This is my first line
Added line 1
edit> This is my second line
Added line 2
edit> :wq
File saved and quit (2 lines)

Muski-shell: /home/user/projects>
cd ~

Muski-shell: /home/user>
exit

๐Ÿ”ฎ Future Ideas

Planned Features

1. I/O Redirection (High Priority)

  • Output redirection: ls > output.txt
  • Input redirection: cat < input.txt
  • Append mode: echo "text" >> file.txt
  • Error redirection: command 2> error.log

2. Pipes (High Priority)

  • Chain commands: ls | grep .txt
  • Multiple pipes: cat file.txt | grep pattern | wc -l

3. Background Processes

  • Run processes in background: command &
  • Job control: jobs, fg, bg
  • Process status display

4. Command History

  • Arrow key navigation (โ†‘/โ†“)
  • history command to view past commands
  • !n to execute command n from history
  • Persistent history across sessions

5. Tab Completion

  • Auto-complete file and directory names
  • Command name completion
  • Path completion with multiple suggestions

6. Advanced Text Editor

  • Insert/replace mode switching
  • Line editing (insert at position)
  • Search and replace functionality
  • Undo/redo capability
  • Syntax highlighting
  • Multiple buffer support

7. Signal Handling

  • Ctrl+C to interrupt current process
  • Ctrl+Z to suspend processes
  • Proper cleanup on signals

๐Ÿ› ๏ธ Technical Details

System Calls Used

  • fork() - Create child processes
  • execv() - Execute external commands
  • wait() - Wait for child process completion
  • chdir() - Change working directory
  • getcwd() - Get current working directory
  • opendir(), readdir(), closedir() - Directory operations
  • stat() - File information

Key Concepts

  • Process Management: Parent-child process relationships
  • File Descriptors: Standard input/output/error
  • Path Resolution: Finding executables in custom paths
  • String Parsing: Tokenizing command-line input
  • Error Handling: Proper cleanup and error messages

๐Ÿ› Known Limitations

  • No pipe support yet
  • No I/O redirection
  • No signal handling (Ctrl+C kills entire shell)
  • Limited command history
  • No tab completion
  • Commands must be in /build directory

๐Ÿค Contributing

This is a learning project! Feel free to:

  • Add new commands
  • Implement planned features
  • Fix bugs
  • Improve documentation

๐Ÿ“ License

This project is for educational purposes. Feel free to use and modify.

๐Ÿ‘จโ€๐Ÿ’ป Author

Built with โค๏ธ to learn systems programming and shell internals.


Note: This shell is a learning project and not intended for production use. For daily work, use bash, zsh, or other mature shells.

About

A lightweight, customizable shell implementation written in C, designed for efficiency and extensibility. Features command history, pipelines, and custom aliases for muskiteers.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages