Skip to content

Thundercloud12/os-mpr

Repository files navigation

Smart Mini Shell in Go

A clean, modular, and demo-ready CLI-based shell application written in Go. It supports standard command execution along with enhanced usability features like pipes, command history, custom shortcuts, and an embedded AI assistant powered by the Groq API.

Features

  • Interactive Shell Loop: Custom Unicode-styled prompt showing current directory.
  • Command Execution: Parses space-delimited inputs and executes system binaries (ls, pwd) natively.
  • Pipe Support: Connects standard I/O streams seamlessly between sequential commands (e.g., ls | grep go).
  • ⚡ Execution Timing: Automatic command execution timing display (green for fast, yellow for medium, red for slow).
  • ✨ Formatted History: View command history with timestamps in a beautiful table format.
  • Built-in Commands:
    • cd <dir>: Change the current working directory.
    • history: View previously executed commands with formatted table display.
    • help [cmd]: Show help for a specific command or all commands.
    • search_history: Fuzzy search through command history.
    • dashboard: Show a beautiful dashboard with system info, git status, and recent commands.
    • clear: Clear the terminal screen.
    • exit: Terminate the shell.
  • History Persistence: Automatically saves and loads your command history to/from ~/.myshell_history.
  • Smart Correction: Levenshtein-distance typo detection for unknown commands (e.g., gti -> git).
  • 🎨 Beautiful UI Elements:
    • Colored output with semantic icons (✓, ✗, ⚠, ℹ)
    • Status messages with context-aware colors
    • Helpful hints displayed on startup
  • Command Autocomplete: Get suggestions as you type commands.
  • Groq AI Assistant: Built-in natural language to CLI translations using LLaMA models.
    • The -exec flag: Append -exec to your natural language prompt and the AI will auto-generate and immediately execute the suggested command in your shell loop.
  • Custom Scripts: Shortcuts like open google or myip directly integrated into the parser.

Architecture

The source code is organized clearly for a highly modular feature addition experience:

  • main.go: Entry point, input loop, and core routing logic.
  • parser.go: Command parsing split logic mapping commands sequentially or breaking piped chunks.
  • executor.go: Subprocess control and standard program loading with timing.
  • builtins.go: Native Go overrides simulating standard core utilities.
  • pipeline.go: I/O orchestrator for executing sequential programs safely with timing.
  • suggestions.go: Autocomplete and correction logic implementation.
  • custom.go: Custom workflow mappings.
  • ai.go: Integration with Groq API.
  • NEW ui.go: Terminal styling, colors, and formatted output functions.
  • NEW history_search.go: Fuzzy search and interactive history navigation.
  • NEW autocomplete.go: Command and file completion suggestions.
  • NEW dashboard.go: Interactive dashboard showing system info and git status.
  • NEW timing.go: Command execution timing and performance tracking.

Prerequisites

  • Go 1.21+ installed on your system.
  • (Optional) A valid Groq API Key to utilize the AI Assistant feature.

Building and Running

  1. Clone or navigate to the project directory:

    cd os-mpr
  2. Compile the binary:

    go build -o myshell
  3. Add your Groq API key:

    export GROQ_API_KEY="your_api_key_here"
  4. Launch the shell:

    ./myshell

Example Usage of AI Integration

You can easily translate plain English text directly into Linux commands inside the shell. Try opening ./myshell and running:

myshell> ai check what process is taking the highest memory -exec

The AI will output and run the pipeline securely:

❖ AI Assistant [command] (100% confidence)
Show which process is taking the most memory. Sorted by memory usage in descending order and show the top result.
Executing: ps aux | sort -rn -k 4 | head -1
...

Phase 1 & 2: UI Enhancements

Execution Timing

Commands automatically display execution time after completion:

myshell> ls
[0.01s]  ← Green for fast commands

Enhanced History Display

Get a formatted view of your command history:

myshell> history
 Command History (18)
────────────────────────────────────────
    1 [2026-04-01 20:58:37] help
    2 [2026-04-01 20:58:56] pwd
    3 [2026-04-01 20:58:56] history
────────────────────────────────────────
  Total commands: 18

Help System

Get help for any command:

myshell> help cd
 Help: Change directory: cd <path>

myshell> help
 Available Commands
────────────────────────────────────────
  cd <path>            Change directory
  exit                 Exit the shell
  history              Show command history
  ...

Dashboard

View a beautiful dashboard with system info, recent commands, and git status:

myshell> dashboard
╔══════════════════════════════════════╗
║    🚀 MYSHELL Dashboard             ║
╚══════════════════════════════════════╝

📊 System Information
──────────────────────
  Hostname: my-machine
  User: keerthan
  OS: linux
  Working Directory: ~/os-mpr

📜 Recent Commands (Last 5)
──────────────────────
  1. help
  2. pwd
  3. history

📦 Git Status
──────────────────────
  Branch: main
  Status: 2 changes

History Search

Fuzzy search through your command history:

myshell> search_history

Shows matching commands from your history for quick re-execution.

Status Messages

Commands provide visual feedback:

✓ Success message  ← Green checkmark
✗ Error message    ← Red X
⚠ Warning message  ← Yellow exclamation
ℹ Info message     ← Blue information icon

Tips & Hints

Helpful hints are displayed at startup:

💡 Tip: Type 'help' for commands, 'Ctrl+R' for history search, or 'dashboard' for overview

Colored, Formatted Output

All output uses semantic colors:

  • Green for success and important paths
  • Yellow for warnings and suggestions
  • Blue for information
  • Cyan for headers and titles
  • Red for errors
  • Gray for secondary information

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages