py-ai-shell
AI-powered shell assistant that generates and explains shell commands based on natural language prompts.
py-ai-shell transforms your natural language descriptions into shell commands, explains what they do, and helps you fix errors. It's like having a shell expert by your side, making command-line work more accessible and efficient.
Installation
pip install py-ai-shell
Requirements:
- Python 3.8 or higher
- OpenAI API key
py-ai-shell works on Linux, macOS, and Windows with support for bash, zsh, fish, and PowerShell.
Quick Start
Basic Usage
# Start py-ai-shell interactive mode
ai
# Run with a one-time prompt
ai "list all files in the current directory"
# Configure py-ai-shell
ai config set OPENAI_KEY=your_api_key
When you run a command, py-ai-shell will:
- Generate the appropriate shell command
- Show you what it's going to do
- Execute the command when you approve
- Provide explanations and error analysis if needed
Features
- Natural Language Command Generation: Convert plain English to shell commands
- Command Explanations: Understand what commands do before running them
- Error Analysis: Get explanations and suggestions when commands fail
- Command History: py-ai-shell remembers context from previous commands
- Multiple Shell Support: Works with bash, zsh, fish, and PowerShell
- Interactive Mode: Full interactive shell experience
- One-off Mode: Quick command generation without entering interactive mode
- Configurable: Use different OpenAI models and customize behavior
- Copy to Clipboard: Easily copy generated commands
- Silent Mode: Less verbose output for experienced users
Configuration
py-ai-shell can be configured using the config command:
# Set your OpenAI API key
ai config set OPENAI_KEY=your_api_key
# Set the model to use (default: gpt-4.1-nano)
ai config set MODEL=gpt-4.1-nano
# Enable silent mode (less verbose output)
ai config set SILENT_MODE=true
# Set API endpoint (useful for proxies or alternative providers)
ai config set OPENAI_API_ENDPOINT=https://api.openai.com/v1
# Set language (default: en)
ai config set LANGUAGE=en
Configuration is stored in ~/.config/py-ai-shell/config.ini and can be edited directly.
Advanced Usage
Command Options
# Run in silent mode (less verbose output)
ai -s "list files by size"
# Provide a custom prompt
ai -p "show disk usage"
Error Analysis
When a command fails, py-ai-shell can analyze the error and suggest fixes:
$ ai "find files modified in the last 24 hours"
# If the command fails, py-ai-shell will offer to analyze the error
Command failed. Would you like an explanation? (?/??/???)
Enter ? for a brief explanation, ?? for a standard explanation, or ??? for a detailed analysis.
Command History
py-ai-shell maintains a history of your recent commands and their results, providing context for future commands. This helps the AI understand your environment and previous actions.
Interactive Options
After a command is generated, you'll see options:
a/A: Accept and run the commande/E: Edit the command before runningr/R: Revise (ask AI to generate a new command)c/C: Copy the command to clipboards/S: Stick to your original commandq/Q: Quit/cancel
Using with Different Shells
py-ai-shell automatically detects your current shell, but you can generate commands for specific shells by mentioning them in your prompt:
ai "list all processes in PowerShell syntax"
Development
Setting Up Development Environment
-
Clone the repository:
git clone https://github.com/cheney-yan/py-ai-shell.git cd py-ai-shell
-
Install development dependencies:
make dev
Available Make Commands
make help: Show available commandsmake clean: Remove all build, test, coverage and Python artifactsmake lint: Check style with flake8make test: Run testsmake coverage: Check code coveragemake dist: Package for distributionmake install: Install the package locallymake dev: Install development dependencies
Contributing
Contributions are welcome! Here's how you can contribute:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure your code passes all tests and linting checks before submitting a pull request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Credits
- This project is inspired by the AI Shell project
- Built with OpenAI API
- Command-line interface powered by Click
- Terminal styling with Rich
Metadata
Release files for py-ai-shell 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py_ai_shell-0.1.3.tar.gz | 26.2 kB | Without provenance | Details for py_ai_shell-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_ai_shell-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for py_ai_shell-0.1.3-py3-none-any.whl |
Total release size: 54.7 kB
Release files / py_ai_shell-0.1.3.tar.gz
| Download URL | py_ai_shell-0.1.3.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a493481b72b46a4e9822216496d7df2107fafad566ec3c6703c2440b012e1b51
|
|
BLAKE2b-256 checksum How to use checksums |
79373c081ea5239f8e7b33ad6f74caff360c222fd78a9ca7cd89ee51a07f9ac3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.6
|
Release files / py_ai_shell-0.1.3-py3-none-any.whl
| Download URL | py_ai_shell-0.1.3-py3-none-any.whl |
|---|---|
| Size | 28.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af7c3286fb26c87c3db51485221ac4f24f2f9ff437db14e9943e855e38758413
|
|
BLAKE2b-256 checksum How to use checksums |
ba286d732f44e8d94bf14e327781cc9bc5697df80239b5998a488cc942f98ca0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.6
|
Security for py-ai-shell 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.