Bash replacement library for Python
Project description
minishell
An idiot admires complexity, a genius admires simplicity
©️ Legend Terry A. Davis
I want to ditch Bash and replace all use cases of it with Python. I recently learned that there's no good alternative for Bash. You can argue that there is, but then compare what they can write in Bash and how unreadable it becomes with any of the traditional shell solutions out there.
Goals
minishellis going to be extremely simple- Compete with Bash only
- Do not add features just because other libraries have them
- Stay focused: execute commands and parse arguments, nothing more
Philosophy
Bash works because it's the shell. You can't replicate that. But you can make Python script writing as painless as Bash for everything else: better error handling, better argument parsing, better readability.
minishell provides just what you need:
shell(cmd, *args, **kwargs)- Run commands with full TTY support and optional argument escapingshell[cmd, *args, **kwargs]- Same as previous, but capture outputshell.args[1], shell.args.named_argument- Parse CLI arguments automatically
That's it. No frameworks, no magic.
Quick Start
# Raw command
shell("ls -la | grep test")
# With escaped arguments (safe!)
filename = "file with spaces.txt"
shell("rm {}", filename)
# Capture output
output = shell["pwd"]
print("Current dir:", output)
# Arguments are auto-parsed
app_name = shell.args.app_name
if not app_name:
shell.exit("Error: --app-name required")
Main API
There are more things, but you may need to read source code.
shell(cmd, *args, **kwargs)
Execute a command with optional argument escaping.
- cmd: Command string with optional
{}placeholders - args: Positional arguments to format and escape
- kwargs: Named arguments to format and escape
# raw
shell("echo hello")
# positional escaping
shell("echo {}", "hello")
# named escaping
shell("git commit -m {message}", message="Fix#147")
shell[cmd, *args]
Execute command and capture output. Returns the output string.
- cmd: Command string with optional
{}placeholders - args: Positional arguments to format and escape
output = shell["pwd"]
# With escaped arguments
output = shell["find {} -name {}", "/path", "*.py"]
shell.args
Automatically parsed command-line arguments.
# Positional
print(shell.args[0])
# Named arguments
print(shell.args.config)
print(shell.args.verbose)
# Multiple values become lists
if isinstance(shell.args.file, list):
for f in shell.args.file:
print(f)
Installation
pip install minishell
Or just copy minishell.py to your project.
Why not Bash?
| Feature | Bash | minishell |
|---|---|---|
| Argument parsing | 50+ lines | 3 lines |
| Variable syntax | $VAR, ${VAR} |
f-strings |
| Error handling | set -e (fragile) |
Explicit |
| Type hints | None | Full typing |
| Readability | Medium | High |
Contributing
We need Bash specialists to provide code examples that are:
- Cleaner/simpler in Bash than in Python with
minishell - Real-world use cases we should optimize for
Alternatively, suggest improvements to keep the library minimal and focused. Pure critique without suggestions is also appreciated!
The bar for adding features: Does this save significant boilerplate compared to Bash?
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file minishell-2.0.18.tar.gz.
File metadata
- Download URL: minishell-2.0.18.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8ce0be76eda829c044b8fed62fcb271d01d5c565886c501a44bf277135bbf5
|
|
| MD5 |
5a5f0979b8ce73759000baf12a4b586f
|
|
| BLAKE2b-256 |
7f459c6de24f0a8428456e6fc38c3de512418c5011b73a6870039c10da196f23
|
File details
Details for the file minishell-2.0.18-py3-none-any.whl.
File metadata
- Download URL: minishell-2.0.18-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc7e6dfc05d5775e1716052e88daa07e81aa9722ab39d9247372401ad87e79e9
|
|
| MD5 |
4b7c7eebadfda3e6ebd9b343ee4896ba
|
|
| BLAKE2b-256 |
3a9c34890ac760f276fc94a6069a3b5f78c44284f2ca3101eeaf56d43ebf1a87
|