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 implemented in Python with advanced scripting capabilities.

โœจ 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: Comprehensive variable 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 patterns
  • Built-in Commands: 50+ built-ins including cd, echo, test, export, local, etc.
  • Job Control: Background jobs with fg/bg commands
  • History & Completion: Command history with readline integration
  • Aliases: Command aliasing support
  • Cross-Platform: Works on Linux, macOS, and Windows

๐Ÿš€ Installation

From Source

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

Using pip (once published)

pip install pyshell-terminal

๐Ÿ“– 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! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the 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

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Inspired by Bash, Zsh, and other Unix shells
  • Built with 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.0.4.tar.gz (51.9 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.0.4-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyshell_terminal-1.0.4.tar.gz
  • Upload date:
  • Size: 51.9 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.0.4.tar.gz
Algorithm Hash digest
SHA256 0475fe5ff6fdf75cf70975ce1dfe8214f8fdef087a052cae98d253a75c58d0a2
MD5 8510b2dbec60d1543f3cb47c729818ef
BLAKE2b-256 9c3c7b662c3949dba8169ecb14d82a594e84fa82f567c1af78e32ff64289329b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pyshell_terminal-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a4d3f464438bb1224a755148378f9838872a7c4e5e748f92a986677a22005af9
MD5 3c5704feba0282ba69208e9674ffb808
BLAKE2b-256 ade2d675d113d760ced80379210cb1ad4d1cf7adf84073aa07fd597e6c27f957

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