Skip to content

yogvidwankhede/PyShell

Repository files navigation

🐚 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

About

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.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages