A POSIX-compliant shell implementation in Rust. This project was originally built as part of the CodeCrafters Shell Challenge and has been extended with additional features and improvements.
exit- Exit the shell with history persistenceecho <text>- Print text to stdoutpwd- Print current working directorycd <path>- Change directory (supports~for home directory)type <command>- Show command type (builtin vs external program location)history [options]- Command history managementhistory- Show all historyhistory <n>- Show last n commandshistory -r <file>- Read history from filehistory -w <file>- Write history to filehistory -a <file>- Append new history to file
- Command Line Editing
- Arrow key navigation (↑/↓ for history browsing)
- Backspace for character deletion
- Raw mode terminal input with proper cleanup
- Tab Completion
- Auto-completion for commands and executables in PATH
- Common prefix completion for multiple matches
- Press tab twice to show all available completions
- History Management
- Persistent history across sessions (via
HISTFILEenvironment variable) - In-memory history with navigation
- History file operations (read/write/append)
- Persistent history across sessions (via
- Shell Word Splitting with proper quote handling:
- Single quotes (
'text') - literal strings - Double quotes (
"text") - variable expansion context - Backslash escaping for special characters
- Single quotes (
- Pipeline Support - Full pipe chains:
cmd1 | cmd2 | cmd3 - I/O Redirection:
- Output redirection:
>,1>,>> - Error redirection:
2>,2>> - Append mode:
>>,1>>,2>> - Mixed redirections:
cmd >stdout.txt 2>stderr.txt
- Output redirection:
- PATH Resolution - Automatic lookup of executables in system PATH
- Process Management - Proper spawning and waiting for child processes
- Signal Handling - Ctrl+C and Ctrl+D support
The shell is organized into focused modules:
main.rs- Core execution pipeline and process managementreadline.rs- Interactive terminal input with editing capabilitiestokenize.rs- Command parsing and token generationwords.rs- Shell word splitting with quote/escape handlingcmd.rs- Built-in command implementationshistory.rs- Command history management and persistencepaths.rs- PATH environment variable processingcmp.rs- Tab completion using trie data structureerrors.rs- Comprehensive error handling
# Install from source
git clone https://github.com/nikiyerm/nikis_shell
cd nikis_shell
cargo install --path .
# Run the shell
nikis_shell
# Or compile and run directly
cargo run$ echo "Hello, World!"
Hello, World!
$ pwd
/home/user/projects
$ cd /tmp
$ ls -la | grep txt > text_files.txt
$ history 5
1 echo "Hello, World!"
2 pwd
3 cd /tmp
4 ls -la | grep txt > text_files.txt
5 history 5
$ type ls
ls is /usr/bin/ls
$ exit- Memory Safety: Built with Rust's ownership system for safe memory management
- Concurrent Access: Thread-safe history and completion using
LazyLockandMutex - Error Handling: Comprehensive error types for different failure modes
- Testing: Extensive unit tests for tokenization and word splitting
- Performance: Efficient trie-based completion and lazy initialization of system paths
The following core shell features are not yet implemented:
- Variable Expansion -
$VAR,${VAR}, environment variable substitution - Globbing/Wildcards -
*.txt,file?.log,[a-z]*pattern matching - Input Redirection -
<for reading from files - Command Substitution -
`command`and$(command) - Background Jobs -
command &and basic job control - Quoting Edge Cases - Better handling of complex quote combinations
- Exit Codes - Proper exit code propagation from commands
- Signal Handling - Improved Ctrl+C, Ctrl+Z behavior
- More Built-ins -
alias,unalias,export,unset,which