A modern, Windows-native interactive command-line shell written in Python.
Overview • Features • Architecture • Setup & Usage • Built-in Commands • Project Structure
PyWinShell is a feature-rich, high-performance command-line shell built specifically for the Windows OS environment using Python. PyWinShell bridges the gap between Unix-style REPL pipelines (|, >, >>, <) and native Windows operating system primitives (Win32 API interop, Windows Registry queries, process token elevation checks, and NTFS path conventions).
Designed with a modular compiler-style architecture, PyWinShell includes custom Lexing, AST Pipeline Parsing, Process Stream Supervision, and an interactive REPL with dynamic autocompletion.
Note
PyWinShell automatically detects Windows Administrator privilege elevation tokens (IsUserAnAdmin) and dynamically adjusts prompt indicators and execution security.
-
🪟 Native Windows OS Integration:
- Elevated Privilege Detection: Real-time detection of Administrator tokens (
⚡ ADMIN). - Windows Registry Inspector: Built-in tool (
reg query) to inspectHKCUandHKLMhives directly. - Windows Task Manager (
task): List processes, view parent-child process trees (task tree), terminate (task kill), suspend, and resume process execution. - Drive Letter Navigation: Seamless directory navigation supporting Windows drive switching (e.g.
D:,C:).
- Elevated Privilege Detection: Real-time detection of Administrator tokens (
-
🎨 Modern Interactive REPL:
- Dynamic Multi-Segment Prompt: Displays elevation status, current path (shortened
~), Git branch indicators, and status arrows. - Intelligent Autocomplete: Tab completion for built-ins, custom aliases, PATH executables (
.exe,.bat,.cmd,.ps1), and file paths. - Persistent Command History: Maintains command history across sessions saved to
~/.pywinshell_history.
- Dynamic Multi-Segment Prompt: Displays elevation status, current path (shortened
-
🔄 Advanced Pipeline & I/O Engine:
- Multi-Stage Pipelines (
|): Pipe data between built-in commands and native Windows executables. - File Redirection (
>,>>,<): Truncate/append output redirection and input stream redirection. - Background Execution (
&): Launch non-blocking background tasks.
- Multi-Stage Pipelines (
-
🛠️ Extensible Alias Engine:
- Define custom shell shortcuts dynamically (e.g.
alias ps='task list'oralias ll='dir').
- Define custom shell shortcuts dynamically (e.g.
PyWinShell uses a multi-layered design separating input processing, AST parsing, and process execution.
flowchart TD
A[User Terminal Input] --> B[Lexer Tokenizer pywinshell/lexer.py]
B -->|Token Stream| C[AST Parser pywinshell/parser.py]
C -->|PipelineNode AST| D[Execution Engine pywinshell/executor.py]
D --> E{Command Type?}
E -->|Built-in Command| F[Builtin Registry pywinshell/builtins/]
E -->|Windows Executable| G[Subprocess Manager Win32 / Popen]
F --> H[Win32 API Utils ctypes / winreg / psutil]
G --> I[Standard I/O Pipes & Redirection]
H --> J[Render Output via Rich & prompt_toolkit]
I --> J
PyWinShell/
│
├── .gitignore
├── README.md
├── requirements.txt
├── setup.py
│
├── pywinshell/
│ ├── __init__.py
│ ├── main.py
│ ├── prompt.py
│ ├── lexer.py
│ ├── parser.py
│ ├── executor.py
│ ├── completion.py
│ ├── win32_utils.py
│ │
│ └── builtins/
│ ├── __init__.py
│ ├── base.py
│ ├── filesystem.py
│ ├── process.py
│ ├── sysinfo.py
│ ├── registry.py
│ ├── env.py
│ ├── history.py
│ └── alias.py
│
└── tests/
├── __init__.py
├── test_lexer.py
├── test_parser.py
└── test_builtins.py
- Operating System: Windows 10 or Windows 11 (64-bit recommended)
- Python Version: Python 3.10 or higher
- Dependencies:
prompt-toolkit(≥ 3.0.0) — Interactive REPL enginerich(≥ 13.0.0) — Terminal formatting, tables, and colorspsutil(≥ 5.9.0) — Process inspection and system metricscolorama(≥ 0.4.6) — Windows ANSI supportpywin32(≥ 306) — Win32 API extensions for Python
-
Clone the repository:
git clone https://github.com/Suchetamon27/PyWinShell.git cd PyWinShell -
Install requirements:
pip install -r requirements.txt
-
Launch PyWinShell:
python -m pywinshell.main
Install PyWinShell in editable mode so you can launch it from any folder in Command Prompt or Windows Terminal:
cd PyWinShell
pip install -e .Now, launch PyWinShell from anywhere by typing:
pywinshell| Command | Description | Usage Example |
|---|---|---|
sysinfo |
Displays Neofetch-style system summary (OS, CPU, RAM, Disk, Uptime, Admin) | sysinfo |
task |
Windows Task Manager utility (subcommands: list, tree, kill, suspend, resume) |
task list or task kill 1234 |
reg |
Queries values from Windows Registry hives (HKCU, HKLM, HKCR, HKU) |
reg query HKCU Software |
winenv |
View and modify environment variables dynamically | winenv get PATH or winenv set FOO bar |
cd |
Change current directory (supports drive letter switching) | cd D:\Projects or cd ~ |
dir |
Formatted directory listing with mode, timestamp, and size | dir or dir C:\Windows |
cat |
Concatenate and display text file content | cat file.txt |
mkdir |
Create new directories | mkdir new_folder |
alias |
Create or view custom command shortcuts | alias ps='task list' |
unalias |
Remove a custom alias | unalias ps |
history |
View history of executed commands in current session | history |
cls / clear |
Clear the terminal screen | cls |
exit / quit |
Exit PyWinShell session | exit |
PyWinShell includes automated unit tests covering the Lexer, Parser, and Built-in Command modules.
Run the test suite using Python's built-in unittest runner:
python -m unittest discover testsDeveloping PyWinShell provided hands-on experience with:
- Low-Level Win32 API Interop: Querying Windows C-APIs (
ctypes.windll.shell32,GetTickCount64) and inspecting Registry keys viawinreg. - Compiler & Lexer Primitives: Building a tokenizer capable of handling quoted arguments, escape codes, pipe symbols (
|), and file redirection operators (>,>>,<). - Subprocess Management: Managing stdin/stdout streams across multi-stage process chains using Python
subprocess.Popen. - Terminal User Experience: Crafting dynamic REPL interfaces with tab completion, history persistence, and rich ANSI visual rendering.
This project is licensed under the MIT License. © 2026 Sucheta Mondal
Made with ❤️ by Sucheta Mondal
