Skip to content

Botan-linux/rato

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyShell - A Modern Python-Based Shell Alternative

PyShell is a powerful, feature-rich shell implemented in pure Python that serves as a modern alternative to traditional shells like bash, fish, and zsh. It combines the power of Python with modern terminal UX principles to create an intuitive and productive command-line experience.

Features

🚀 Core Features

  • Syntax Highlighting: Real-time command syntax highlighting with customizable colors
  • Intelligent Autocomplete: Smart command and file path completion
  • Command History: Persistent history with search functionality
  • Modern Interface: Clean, customizable prompt with git branch display
  • Built-in Commands: Essential shell commands implemented natively
  • Alias System: Create and manage command aliases
  • Configuration: Web-based and file-based configuration options

🎨 Visual Features

  • Rich Terminal Output: Beautiful formatting using the Rich library
  • Multiple Themes: Dark and light theme support
  • Customizable Prompts: Modern and classic prompt styles
  • Git Integration: Automatic git branch detection and display
  • Color-Coded Output: Syntax highlighting for commands, paths, and operators

🔧 Advanced Features

  • Web Configuration: Browser-based configuration interface
  • Plugin System: Extensible architecture for custom functionality
  • Environment Management: Built-in environment variable handling
  • Cross-Platform: Works on Linux, macOS, and Windows
  • Single File: Entire shell in one executable Python file

Installation

Quick Start

# Download the shell
curl -o pyshell.py https://path-to-pyshell/pyshell.py

# Make it executable
chmod +x pyshell.py

# Run the shell
./pyshell.py

Requirements

PyShell requires Python 3.6+ and optionally the following packages for enhanced features:

# Install optional dependencies for enhanced features
pip install rich textual readline

Usage

Starting PyShell

# Basic usage
python pyshell.py

# With custom theme
python pyshell.py --theme dark

# Disable features
python pyshell.py --no-highlighting --no-autocomplete

Built-in Commands

Navigation

  • cd [directory] - Change directory
  • pwd - Print working directory
  • ls - List directory contents (with rich formatting)

Configuration

  • help - Show help information
  • config - Configure shell settings
  • webconfig - Open web-based configuration
  • alias - Manage command aliases

History

  • history - Show recent commands
  • history search <pattern> - Search command history

Other

  • clear - Clear terminal
  • exit or quit - Exit the shell

External Commands

PyShell supports all standard shell commands:

  • File operations: cp, mv, rm, mkdir, touch
  • Text processing: grep, awk, sed, cat, less
  • System commands: ps, top, df, du, whoami
  • Development: git, python, node, npm, docker

Keyboard Shortcuts

  • Ctrl+C - Interrupt current command
  • Ctrl+D - Exit the shell (EOF)
  • Up/Down Arrow - Navigate command history
  • Tab - Autocomplete commands and paths

Configuration

Configuration File

PyShell stores configuration in ~/.pyshell_config.json:

{
  "theme": "dark",
  "prompt_style": "modern",
  "show_git_branch": true,
  "syntax_highlighting": true,
  "autocomplete_enabled": true,
  "aliases": {
    "ll": "ls -la",
    "..": "cd ..",
    "home": "cd ~"
  },
  "environment_vars": {
    "EDITOR": "vim",
    "PYTHONPATH": "/usr/local/lib/python3.9"
  }
}

Web Configuration

Access the web-based configuration interface:

pyshell> webconfig
# Open http://localhost:8080 in your browser

Customization

Themes

PyShell supports multiple color themes:

  • dark (default) - Dark theme with blue accents
  • light - Light theme with soft colors

Prompt Styles

  • modern (default) - Multi-line prompt with git branch
  • classic - Traditional single-line prompt

Aliases

Create custom command aliases:

# Add alias
pyshell> alias add ll "ls -la"

# Remove alias  
alias> alias remove ll

# List aliases
pyshell> alias

Architecture

Core Components

  1. PyShell - Main shell class coordinating all functionality
  2. CommandHistory - Manages command history with persistence
  3. SyntaxHighlighter - Provides real-time syntax highlighting
  4. AutoCompleter - Intelligent command and path completion
  5. ShellConfig - Configuration management and persistence

Key Technologies

  • Rich Library - Beautiful terminal formatting and output
  • Textual - Advanced terminal user interfaces (optional)
  • Readline - Command line editing and history (Unix systems)
  • HTTP Server - Web-based configuration interface

Design Principles

  • Single Responsibility - Each component has a clear purpose
  • Extensibility - Plugin architecture for custom functionality
  • User Experience - Modern, intuitive interface design
  • Performance - Efficient command execution and response
  • Cross-Platform - Works consistently across operating systems

Examples

Daily Usage

# Navigate with style
pyshell> cd /home/user/projects
user@hostname:/home/user/projects (main)
❯ ls

# Use aliases for common tasks
user@hostname:/home/user/projects (main)  
❯ alias add deploy "git push origin main && ssh server 'cd /app && git pull'"

# Search command history
user@hostname:/home/user/projects (main)
❯ history search git

Development Workflow

# Git operations with branch display
user@hostname:/home/user/projects (feature-branch)
❯ git status

# Python development
user@hostname:/home/user/projects (feature-branch)  
❯ python -m pytest tests/

# Docker operations
user@hostname:/home/user/projects (feature-branch)
❯ docker build -t myapp .

Comparison with Other Shells

Feature PyShell Bash Fish Zsh
Syntax Highlighting ✅ Built-in ❌ Plugin ✅ Built-in ✅ Plugin
Autocomplete ✅ Smart ✅ Basic ✅ Advanced ✅ Advanced
Configuration ✅ Web + File ❌ Manual ✅ Web ✅ Manual
Git Integration ✅ Built-in ❌ Manual ✅ Plugin ✅ Plugin
Python Integration ✅ Native ❌ Limited ❌ Limited ❌ Limited
Single File ✅ Yes ❌ No ❌ No ❌ No

Troubleshooting

Common Issues

  1. Colors not showing

    • Ensure terminal supports 256 colors
    • Try --theme light option
    • Check $TERM environment variable
  2. Autocomplete not working

    • Install readline module: pip install readline
    • Enable autocomplete in config: config autocomplete true
  3. Performance issues

    • Disable syntax highlighting: --no-highlighting
    • Reduce history size in config file
    • Check system resources
  4. Web config not loading

    • Ensure port 8080 is available
    • Check firewall settings
    • Try different browser

Getting Help

# Show built-in help
pyshell> help

# Check version
pyshell> python pyshell.py --version

# Verbose mode for debugging
pyshell> python -v pyshell.py

Development

Extending PyShell

PyShell's architecture makes it easy to add new features:

# Add custom command
class PyShell:
    def handle_builtin_command(self, command: str) -> bool:
        if command == "mycommand":
            print("My custom command!")
            return True
        return super().handle_builtin_command(command)

Plugin System

Create plugins by extending the base functionality:

class PyShellPlugin:
    def __init__(self, shell):
        self.shell = shell
    
    def register_commands(self):
        self.shell.register_command("myplugin", self.my_command)
    
    def my_command(self, args):
        print("Plugin command executed!")

License

PyShell is released under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit pull requests or report issues.

Acknowledgments

  • Inspired by modern shells like Fish and Zsh
  • Built with the excellent Rich library for beautiful terminal output
  • Thanks to the Python community for the powerful ecosystem

About

shell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages