{"id":25957627,"url":"https://github.com/krikera/python-shell-exp","last_synced_at":"2026-04-20T04:02:39.637Z","repository":{"id":279810526,"uuid":"940054182","full_name":"krikera/python-shell-exp","owner":"krikera","description":"A lightweight command-line shell emulator written in Python.","archived":false,"fork":false,"pushed_at":"2025-03-07T05:33:36.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-07T06:26:35.752Z","etag":null,"topics":["basics","python","shell"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/krikera.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-27T14:41:09.000Z","updated_at":"2025-03-07T05:33:39.000Z","dependencies_parsed_at":"2025-02-27T21:04:53.918Z","dependency_job_id":"730fa30e-3ff1-468e-a85c-d1e650a6b59d","html_url":"https://github.com/krikera/python-shell-exp","commit_stats":null,"previous_names":["krikera/python-shell-exp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/krikera/python-shell-exp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krikera%2Fpython-shell-exp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krikera%2Fpython-shell-exp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krikera%2Fpython-shell-exp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krikera%2Fpython-shell-exp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/krikera","download_url":"https://codeload.github.com/krikera/python-shell-exp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/krikera%2Fpython-shell-exp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32032302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["basics","python","shell"],"created_at":"2025-03-04T17:35:54.553Z","updated_at":"2026-04-20T04:02:39.623Z","avatar_url":"https://github.com/krikera.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Shell Emulator\n\nThis project is a lightweight command-line shell emulator written in Python. It implements basic command execution, tab completion, redirection features, command history, and pipeline functionality similar to those found in traditional Unix shells.\n\n## Features\n\n- **Tab Completion**:  \n  Automatically completes both built-in commands and external executables found in your system's `PATH`.\n\n- **Command History**:  \n  - Tracks commands entered during the current and previous sessions\n  - Navigate through history using up/down arrow keys\n  - View command history with the `history` command\n  - Limit history display with `history N` (shows last N commands)\n  - History persists between shell sessions in `~/.python_shell_history`\n  - Supports redirection of history output to files\n\n- **Built-in Commands**:  \n  Supports a handful of common built-ins including:\n  - `type`: Identifies whether a command is a shell built-in or an external executable.\n  - `cd`: Changes the current working directory.\n  - `exit`: Exits the shell.\n  - `pwd`: Prints the current working directory.\n  - `echo`: Displays text on the terminal.\n  - `export`: Sets or displays environment variables.\n  - `history`: Displays command history.\n  - `help`: Displays information about built-in commands.\n\n- **Command Redirection**:  \n  Basic support for redirecting input, output, and errors:\n  - `\u003e` or `1\u003e`: Redirect standard output to a file (write mode).\n  - `\u003e\u003e` or `1\u003e\u003e`: Redirect standard output to a file (append mode).\n  - `2\u003e`: Redirect standard error to a file (write mode).\n  - `2\u003e\u003e`: Redirect standard error to a file (append mode).\n  - `\u003c`: Redirect standard input from a file.\n\n- **Pipes**:  \n  Connect multiple commands together with the pipe operator (`|`):\n  - Redirect the output of one command as input to another\n  - Chain multiple commands together in a pipeline\n  - Combine pipes with redirections for complex command sequences\n  - Both built-in and external commands support piping\n\n- **Environment Variables**:  \n  Full support for environment variable management:\n  - Set variables using `export VAR=value`.\n  - Use variables in commands with `$VAR` or `${VAR}` syntax.\n  - Access special variables like `$$` (process ID) and `$?` (exit code).\n  - Variables persist throughout the shell session.\n  - View all variables using `export` without argument.\n\n- **Tilde Expansion**:  \n  Support for using `~` as a shortcut:\n  - Standalone `~` expands to the user's home directory\n  - Paths starting with `~/` expand to paths relative to home\n  - `~username/` expands to another user's home directory\n  - Works in all contexts where paths are expected\n\n- **Help System**:  \n  Documentation for built-in commands:\n  - `help` lists all available built-in commands\n  - `help command` provides detailed help on a specific command\n  - Includes syntax, description, and usage information\n  - Supports redirection and can be used in pipes\n\n- **External Command Execution**:  \n  Executes external commands by searching for them in your system's `PATH` with proper error handling for cases like command not found or permission issues.\n\n## Requirements\n\n- **Python 3.x**\n- Standard Python libraries:\n  - `sys`\n  - `os`\n  - `shutil`\n  - `subprocess`\n  - `shlex`\n  - `readline`\n  - `re`\n  - `atexit`\n\n## Usage\n\n1. **Run the Shell**:  \n   Execute the script from the terminal:\n   ```bash\n   python main.py\n   ```\n\n2. **Environment Variable Examples**:\n\n   - **Set a variable**:\n     ```bash\n     export NAME=World\n     ```\n\n   - **Use variables in commands**:\n     ```bash\n     echo \"Hello $NAME\"\n     ```\n\n   - **Check exit codes**:\n     ```bash\n     ls /nonexistent\n     echo $?\n     ```\n\n3. **Command History Examples**:\n\n   - **View all command history**:\n     ```bash\n     history\n     ```\n\n   - **View last 5 commands**:\n     ```bash\n     history 5\n     ```\n\n   - **Save history to a file**:\n     ```bash\n     history \u003e my_history.txt\n     ```\n\n   - **Navigate history**: Press up/down arrow keys to cycle through previous commands\n\n4. **Pipe Examples**:\n\n   - **Basic pipe to filter output**:\n     ```bash\n     ls | grep .py\n     ```\n\n   - **Chain multiple commands**:\n     ```bash\n     ls -la | grep \"^d\" | sort\n     ```\n\n   - **Combine pipes with redirections**:\n     ```bash\n     ls | grep .txt \u003e text_files.txt\n     ```\n\n   - **Use built-in commands in pipes**:\n     ```bash\n     echo \"Hello World\" | grep \"Hello\"\n     ```\n\n   - **Count items with pipes**:\n     ```bash\n     ls | wc -l\n     ```\n\n5. **Tilde Expansion Examples**:\n\n   - **Navigate to home directory**:\n     ```bash\n     cd ~\n     ```\n\n   - **List files in home subdirectory**:\n     ```bash\n     ls ~/Documents\n     ```\n\n   - **Create file in home directory**:\n     ```bash\n     echo \"test\" \u003e ~/testfile.txt\n     ```\n\n6. **Help Examples**:\n\n   - **View available commands**:\n     ```bash\n     help\n     ```\n\n   - **Get help on specific command**:\n     ```bash\n     help cd\n     help export\n     ```\n\n   - **Save command help to file**:\n     ```bash\n     help echo \u003e echo_help.txt\n     ```\n\n   - **Search through command help**:\n     ```bash\n     help | grep directory\n     ```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrikera%2Fpython-shell-exp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkrikera%2Fpython-shell-exp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkrikera%2Fpython-shell-exp/lists"}