Skip to content

0Emperor/0-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 

Repository files navigation

0-shell

A simple, lightweight shell implementation written in Rust.

0-shell mimics the functionality of a standard Unix shell, providing built-in implementations for common commands and handling basic shell features like command parsing and quoting.

features

  • Interactive Shell Loop: A classic REPL (Read-Eval-Print Loop) interface.
  • Command Parsing: robust parsing of input, including handling of quoted strings (single and double quotes).
  • Built-in Commands: Pure Rust implementations of standard core utils:
    • echo: Print text to standard output.
    • pwd: Print the current working directory.
    • cd: Change the current directory.
    • ls: List directory contents (supports colors and permissions if configured).
    • mkdir: Create new directories.
    • cat: Concatenate and display file contents.
    • cp: Copy files and directories.
    • mv: Move or rename files and directories.
    • rm: Remove files and directories.
    • clear: Clear the terminal screen.
    • exit: Exit the shell.

prerequisites

Before you begin, ensure you have the Rust programming language and Cargo package manager installed on your system.

You can install Rust using rustup:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

installation & running

  1. Clone the repository (if you haven't already):

    git clone <repository_url>
    cd 0-shell
  2. Run the shell directly using Cargo: This will compile dependencies and start the shell in one go.

    cargo run
  3. Build a release binary (optional): For better performance, you can build a release version:

    cargo build --release
    ./target/release/0-shell

usage

Once the shell is running, you will see the prompt:

$ 

You can type standard commands just like in bash or zsh.

examples

Listing files:

$ ls
Cargo.toml src target

Creating and entering a directory:

$ mkdir new_folder
$ cd new_folder
$ pwd
/path/to/0-shell/new_folder

Creating a file (using echo) and reading it:

$ echo "Hello World" > hello.txt  # Note: Redirection support depends on implementation details
$ cat hello.txt
Hello World

(Note: If file redirection > is not fully implemented in the parser yet, echo will simply print the arguments).

Handling Consoles/Quotes: The shell supports multi-line input if a quote is left open:

$ echo "this is a 
dequote> multi-line string"
this is a
multi-line string

project structure

  • src/main.rs: The entry point and main loop of the shell.
  • src/parse.rs: Logic for parsing command-line input and handling quotes.
  • src/commands/: Individual modules for each built-in command (ls, cd, echo, etc.).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages