Skip to content

Repository files navigation

komi.sh 🌸

A UNIX-ish shell built from scratch

komi.sh is a custom shell written in C. No flex, no bison, no parser generators like antlr.
It uses a handcrafted lexer, recursive descent parser, and builds an AST to interpret commands like any other shell. I built it mainly to serve as a step towards Compiler Construction.

But here's something: it comes with komi — a shy, philosophical AI assistant powered by groq; more like a shitty wrapper on some llm like every other ai startup.


🚀 Features

  • 🔤 Custom Lexical Analyzer & Recursive Descent Parser

  • 🌲 AST Construction & Traversal for Execution

  • 🧵 Token Support:

    • TOKEN_WORD, TOKEN_STRING
    • |, ||, &&, >, >>, <, &
  • 🔌 Pipe chaining, redirection, background execution, etc

  • 🧠 Built-in AI assistant with komi command

    • komi [prompt] talks to Groq LLM in Komi's shy persona Komi Shell demo
  • 🧪 Environment Detection:

    • C or C++ Makerfile (🖇️)
    • Python venv (📦)
    • Git repo (🔧)
    • Node.js (📁 package.json)
    • Rust (🦀 Cargo.toml)
    • Go (🐹 go.mod)
  • ✅ Git branch detection, help page(komi -h), and history (komi --past)

  • 🎨 Minimalist Komi-themed prompt, emoji-aware if terminal supports

  • ⚙️ Signal handling for arrow keys to move up and down the history

  • 📝 Tilde(~) support for max efficiency.


📱 Demo

Komi Shell builtin Komi Shell Redirect Komi Shell pipes Komi Shell bg Komi Shell Ai Komi Shell builtin


🛠️ Setup & Run

git clone https://github.com/kush1jpeg/komi.sh.git
cd komi.sh
make run        --to Run after compiling

To use AI, insert your Groq API key in the file (komiCmds.c):

eg - Authorization: Bearer gsk_...

📊 Architecture, AST and Hierarchy -


                  [ The shit moves like ]
                           |
              +------------+------------+
              |                         |
         [ BG / FG ]              [ BG / FG ]
              |                         |
         [ PIPE Node ]             [ PIPE Node ]
              |                         |
      +-------+-------+         +-------+-------+
      |               |         |               |
[ REDIRECT Node ]  [ CMD ]   [ CMD ]     [ REDIRECT Node ]
      |               |         |               |
 [ FILE Node ]   [ ARGS ]   [ ARGS ]       [ FILE Node ]





Input --> Lexer --> Parser --> AST --> Interpreter --> Execution
                                            └--> komi AI (if used)





bottom to top !
    COMMAND→   words like `ls`, `echo`, etc.
    PIPE->     cmd | cmd
    SEQ->      cmd ; cmd OR && OR ||
    REDIRECT-> >,>>, <
    SEQUENCE-> && , ||
    BG→        &


All of the shell components are written from scratch in C. Handles input parsing, tokenizing, AST creation, execution, and talking to Groq’s LLM.

Parsing-


My views + Improvements + Future plans -

I hated mern cuz everything felt like a copy of a copy of a copy. Connecting different libraries and calling it a creation is just pure idiocy. I needed a break, komi.sh was my way to get free from abstractions, understand the internals of a shell and rebel against languages full of libraries. Not just run commands but build some and fork majority of them.lol.

I made it just because i want to make a compiler in the future and the parser and lexical Analyzer serves the basics for the latter. C is too much tbh, code in C is a beautiful tradgedy, it punishes u with nothing except a SIGSEGV and leaves you questioning your futile existence......though valgrind, objdump, gdb or strace are there but i can't truly understand shit, cuz its majorly asm.

Now that i have made a working shell, I am more confused than ever before, I am more depressed than before and this feeling of incompetency is rising up. I know after making this shell, I know nothing. I feel like i am standing on the pinnacle of impotency. I realized how beautiful and dumb the world full of abstraction was.

..the only good thing that happened after making this project was that, I found a love, C is her name she shines hellishly, like Nastenka, but we all know the end...!

Now i really wanted to make a webserver in C from scratch but it felt like a diff drag so i used libcurl the og library and copied the whole example to make it work along with some gpt. I lowkey want to add some language inside this shell like in bash is bash.....wow!.... lua or bash. let's see if i get bored i would try to do it cuz i think it would be not that difficult as i have the whole Token and ast struct ready. I wanted to make some video renderer inside terminal but it was again a seperate project idea. and yeah also give voice to komi but writing it in barebone c would be soooo difficult...... So yeah i know this shell is not good, and nobody even me would rarely use it, except to flex! lol;


📚 License

This project is licensed under the BSD 2-Clause License.
See LICENSE file for full details.


👤 Author: kush1jpeg

" The shell cant talk much like our girl Komi ! "

About

“A UNIX-ish shell built from scratch. Custom lexer + parser . supports pipes, bg-execution, redirection, etc”

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages