Skip to main content

A feature-rich, POSIX-compatible shell implemented in Python with advanced scripting capabilities.

Project description

🐚 PyShell — A Feature-Rich POSIX-Compatible Shell in Python

PyPI version

License: MIT

Python 3.7+

Website

GitHub Repo

PyPI Project


A feature-rich, POSIX-compatible shell implemented in Python with advanced scripting capabilities.
Cross-platform and extensible, PyShell brings the power of Unix-style scripting to Python environments.


✨ Features

  • POSIX Compatibility: Standard shell syntax (if, while, for, case)
  • Advanced Arrays: Indexed and associative arrays
  • Pipeline Support: Full pipe, redirection, and background job control
  • Function Definitions: Shell functions with local variables
  • Parameter Expansion: ${var:-default}, ${var#pattern}, etc.
  • Command Substitution: $(command) and backtick syntax
  • Arithmetic Expansion: $((expression)) with full math operations
  • Brace Expansion: {1..10}, {a,b,c}
  • Glob Patterns: *, ?, [...] with extended matching
  • Built-in Commands: 50+ built-ins (cd, echo, export, test, local, etc.)
  • Job Control: Background jobs with fg / bg
  • History & Completion: Command history with readline integration
  • Aliases: Command aliasing support
  • Cross-Platform: Works on Linux, macOS, and Windows

🚀 Installation

<<<<<<< HEAD

From Source

git clone https://github.com/yogvidwankhede/PyShell.git
cd pyshell
pip install -e .

Using pip (once published)

=======

pip install pyshell-terminal

From Source

git clone https://github.com/yogvidwankhede/PyShell.git
cd PyShell
pip install -e .

📖 Usage

Interactive Mode

python main.py

Execute Command

python main.py -c "echo Hello World"

Run Script

python main.py script.sh

💡 Examples

Variables and Arrays

# Simple variables
name="PyShell"
echo $name

# Arrays
arr=(one two three)
echo ${arr[0]}
echo ${arr[@]}

# Associative arrays
declare -A config
config[host]="localhost"
config[port]=8080
echo ${config[host]}

Control Flow

# If statements
if [ -f "file.txt" ]; then
    echo "File exists"
else
    echo "File not found"
fi

# Loops
for i in {1..5}; do
    echo "Count: $i"
done

# While loops
count=0
while [ $count -lt 5 ]; do
    echo $count
    count=$((count + 1))
done

Functions

greet() {
    local name=$1
    echo "Hello, $name!"
}

greet "World"

Pipelines and Redirection

# Pipes
cat file.txt | grep "pattern" | wc -l

# Redirection
echo "data" > output.txt
cat input.txt >> output.txt
command 2> errors.log

🏗️ Architecture

pyshell/
├── main.py           # Entry point and REPL
├── pyshell/
│   ├── tokenizer.py  # Lexical analysis
│   ├── parser.py     # Syntax analysis
│   ├── executor.py   # Command execution
│   ├── expansions.py # Variable/command expansion
│   ├── builtins.py   # Built-in commands
│   ├── state.py      # Global shell state
│   ├── ast_nodes.py  # AST node definitions
│   ├── exceptions.py # Custom exceptions
│   └── utils.py      # Utilities
└── tests/            # Test suite

🧪 Testing

python tests/run_all_tests.py

🤝 Contributing

Contributions are welcome! 🙌

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/AmazingFeature
    
  3. Commit your changes
    git commit -m "Add some AmazingFeature"
    
  4. Push to your branch
    git push origin feature/AmazingFeature
    
  5. Open a Pull Request

📝 Roadmap

  • Tab completion improvements
  • More POSIX test operators
  • Process substitution
  • Co-processes
  • Additional shell options
  • Performance optimizations

🙏 Acknowledgments

  • Inspired by Bash, Zsh, and other Unix shells
  • Built using Python’s readline and subprocess modules

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyshell_terminal-1.1.0.tar.gz (52.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyshell_terminal-1.1.0-py3-none-any.whl (42.2 kB view details)

Uploaded Python 3

File details

Details for the file pyshell_terminal-1.1.0.tar.gz.

File metadata

  • Download URL: pyshell_terminal-1.1.0.tar.gz
  • Upload date:
  • Size: 52.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for pyshell_terminal-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4b386002a7a5fa4622f90767400b42fda8551444f1997a71c20fdf3353b2d256
MD5 45bec3245b7d8deebc9f4648ebe25c6c
BLAKE2b-256 71cb6b345fc9a0cf015058ec12065063928891cc4479a66e89b757bdb5ee77fb

See more details on using hashes here.

File details

Details for the file pyshell_terminal-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pyshell_terminal-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf638ecffd63cb509d8dc7d6003e17ea91c951e4394d4b1c6b820cb18771f9e6
MD5 333a4c3c521330baf20fc4f869e73a37
BLAKE2b-256 7345e04625cbc7956eb45d080fdf5e68dc54a00abcb12b493e87257f45021aa7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page