Skip to content

ICEBergJQ/0-shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Shell

A custom Unix-like shell implementation written in Rust. This project provides a basic command-line interface with a REPL (Read-Eval-Print Loop) and built-in implementations of common shell utilities.

Features

Core Shell Functionality

  • REPL Interface: Interactive command prompt ($ or > for multi-line).
  • Command Parsing:
    • Handles single (') and double (") quotes.
    • Supports escape characters (\).
    • Handles multi-line input for unclosed quotes or escapes.
  • Built-in Commands:
    • cd: Change the current working directory.
    • pwd: Print the current working directory.
    • echo: Display a line of text (supports escape sequences like \n, \t, etc.).
    • exit: Terminate the shell session.

Included Utilities

The shell includes custom implementations of standard Unix utilities found in src/commands/:

  • ls: List directory contents.
    • Supports -a (show hidden files).
    • Supports -l (long listing format with permissions, owner, group, size, modification time).
    • Supports -F (classify output with trailing characters like /, @, *).
    • Handles file permissions and coloring/formatting similar to standard ls.
  • cat: Concatenate and display file contents.
  • cp: Copy files and directories.
  • mv: Move or rename files and directories.
  • rm: Remove files or directories (supports -r for recursive deletion).
  • mkdir: Create new directories.

Project Structure

.
├── Cargo.toml          # Project configuration and dependencies
├── src/
│   ├── main.rs         # Entry point
│   ├── shell.rs        # Main REPL loop and input handling
│   ├── parser.rs       # Command string parsing logic
│   └── commands/       # Implementation of shell commands
│       ├── cat.rs
│       ├── cd.rs
│       ├── cp.rs
│       ├── echo.rs
│       ├── ls.rs
│       ├── mkdir.rs
│       ├── mod.rs      # Command dispatcher
│       ├── mv.rs
│       ├── pwd.rs
│       └── rm.rs

Dependencies

  • chrono: Used for formatting time stamps in ls.
  • libc: Used for accessing low-level file permissions and system calls.
  • users: Used for resolving user and group IDs to names in ls.

Getting Started

Prerequisites

  • Rust and Cargo (latest stable version recommended).

Building and Running

  1. Clone the repository (if applicable) or navigate to the project directory.

  2. Build the project:

    cargo build --release
  3. Run the shell:

    cargo run

Usage

Once inside the shell, you can execute commands as you would in a standard Unix shell:

$ ls -la
$ mkdir new_folder
$ cd new_folder
$ echo "Hello, World!" > file.txt
$ cat file.txt
$ cd ..
$ rm -r new_folder
$ exit

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors