An open API service indexing awesome lists of open source software.

https://github.com/corrode/rustlab2024

Write yourself a shell in Rust. A 3-hour course to learn about intermediate Rust concepts and idiomatic code.
https://github.com/corrode/rustlab2024

Last synced: 10 months ago
JSON representation

Write yourself a shell in Rust. A 3-hour course to learn about intermediate Rust concepts and idiomatic code.

Awesome Lists containing this project

README

          

# Write Yourself A Shell in Rust

![Course banner](assets/banner.png)

## Introduction

One of the things developers use every day is a [shell](https://multicians.org/shell.html). It comes in many flavors like `bash`, `fish` or `zsh`. Depending on your background, writing your own shell from scratch might either sound intimidating or pointless. We like to believe that it can be a fun way to gain more hands-on Rust experience. If you want to play with concepts like I/O, error handling, and syscalls we invite you to participate in this workshop. Who knows, it could also be an opportunity to start your first mid-size Rust project?

> [!NOTE]
> Shells are very complex and we will only implement a basic subset of their functionality.
> Take this workshop as an excuse to learn Rust rather than a guide for how to write the perfect shell.

## Who's the Target Audience?

This workshop is intended for *intermediate* Rust programmers who already understand basic Rust concepts and have some programming experience. We’ll explain the rest as we go along.
When we were learning Rust, we always wanted to see a mid-size system being built to get an understanding of how the concepts are put into practice. We think this could be a learning boost for people who are in the same situation as we were.

### Necessary Tools

* [rust](https://www.rust-lang.org/tools/install)
* [git](https://git-scm.com/)

> [!TIP]
> Please, disable AI code completions in your IDE.
> This workshop should be a learning experience and since this repository
> contains the solution, AI code completions will spoil the fun.

## Structure

Use the [slides](./slides.pdf) to go through the exercises.

Use `src/main.rs` to start writing your code.
If you get stuck, check out the [examples](/examples) folder, which contains working source code for each block.
We recommend to try it yourself first and only refer to the example code in case you run into issues.

## Run tests

You can find tests for each block in the `tests` folder.
By default, tests run the example code for each block.
When you are ready to test your own implementation,
comment the `.example()` call in the test and run `cargo test blockN`
(e.g. `cargo test block1`).

## Blocks

Here are the individual blocks of work that we will cover:

* Block 0 - Check Rust Installation and Version
* Block 1 - Running Single Commands
* Block 2 - Concatenating Commands
* Block 3 - Shell Builtins. E.g. `cd`.
* Block 4 - Shell History Support
* Block 5 - Pipes
* Block 6 - Bring your own features!

> [!TIP]
> Ideas for extending your shell in block 6:
> - handling control signals (Ctrl + c, Ctrl + d)
> - redirection
> - command completion
> - adding more builtins
> - use a grammar for parsing
> - Hints for the workshop

## Show And Tell!

We are curious to see what you have built. If you want to share your shell with
us, please send us a link to your repository. We will add it to the list below.

We'd be happy to hear your answers to the following questions:

- What did you learn?
- What was easy?
- What was hard?
- Would you do anything differently?
- What would you like to learn next?

## Closing Words

If you enjoyed this workshop, please share it with your friends and colleagues.
It would greatly help us if you could tweet/toot about it or share it on
[Reddit](https://www.reddit.com/r/rust/) or [LinkedIn](https://www.linkedin.com/).
Thanks!

You might also want to [subscribe to our newsletter](https://corrode.dev/blog/) for
future workshops and other Rust content.

If you are looking for professional Rust training, please get in touch with us
at [corrode.dev](https://corrode.dev/).