A custom shell built from scratch in Python. This project was a fun exploration into how shells work, implementing core functionalities like command parsing, I/O redirection, and process pipelines.
As a unique feature, it also integrates with AI to offer command generation and explanation.
Note: This is a personal project with a limited feature set. It's shared in the hope that it might serve as a useful or interesting starting point for others looking to build their own command-line tools.
- Command Execution: Runs built-in commands (
echo
,exit
,cd
,pwd
,type
,history
) and any external command available in the system's$PATH
. - Pipelines: Chain multiple commands together using the pipe (
|
) operator. - I/O Redirection: Redirect
stdout
(>
,>>
) andstderr
(2>
) to files. - Advanced Input Parsing: Handles single and double quotes, character escaping (
\
), and environment variable expansion ($VAR
). - Tab Completion: Context-aware completion for commands and file paths.
- Persistent History: Saves command history between sessions (requires
HISTFILE
to be set).
do
: Describe a task in plain English, and have the AI generate the shell command for you. Includes a safety check for potentially risky commands.explain
: Get a simple, human-readable explanation of what any shell command does.
A wrapper script run.sh
is provided to easily run the shell or its tests within the virtual environment.
To start an interactive pyShell
session, simply execute:
./run.sh
To run the suite of unit tests for the project, use the -t flag:
./run.sh -t
Once inside pyShell
, you can use it like a standard Unix shell.
$ echo "Hello from pyShell!"
Hello from pyShell!
$ ls -l | wc -l > line_count.txt
$ cd /tmp
$ pwd
/tmp
The first time you use an AI-powered command (do
or explain
), pyShell will prompt you to configure your AI provider settings. These settings are saved to a .pyShell file in your home directory (~/.pyShell) for future sessions.
Let the AI figure out the command for you.
$ do find all files in the current directory that have been modified in the last 24 hours
./pyShell.py
./README.md
Understand what a complex command does before you run it.
$ explain "tar -czvf archive.tar.gz /path/to/directory"
This command creates a compressed archive.
- 'c': Creates a new .tar archive.
- 'z': Compresses the archive with gzip.
- 'v': Verbosely shows the .tar file progress.
- 'f': Specifies the archive file name.
Example: Backing up a project folder.