One of the things developers use every day is a shell. 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.
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.
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.
Use the slides to go through the exercises.
Use src/main.rs
to start writing your code.
If you get stuck, check out the 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.
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
).
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
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?
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 or LinkedIn. Thanks!
You might also want to subscribe to our newsletter for future workshops and other Rust content.
If you are looking for professional Rust training, please get in touch with us at corrode.dev.