Skip to main content

Generate shell commands using OpenAI models.

Project description

Shell Craft

PyPI version

Project for generating shell commands using OpenAI models.

How to install

  1. pip install openai-shell-craft

Command Line Interface

All command line usage follows the following format:

shell-craft <prompt type> "<human request>"

Shell Craft supports many prompt types, such as:

  • Bash
  • Powershell
  • Feature Request

For additional help you can run:

shell-craft --help

Bash Example

shell_craft bash "find all swp files and delete them if theyre not in use"
find . -name '*.swp' -type f ! -exec fuser -s {} \; -delete

Powershell Example

$ shell_craft powershell "remove all files older than 30 days"
Get-ChildItem -Path "C:\your\path" -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-30)} | Remove-Item -Force

Feature Request Example

$ shell_craft feature_request "add an icon that shows the total test coverage"
---

name: Add Total Test Coverage Icon
about: Add an icon that shows the total test coverage
labels: Enhancement

---

**Is your feature request related to a problem? Please describe.**
There is currently no easy way to visualize the total test coverage for a project.

**Describe the solution you'd like**
I would like to have an icon on the project dashboard that, when clicked, displays the total test coverage for the project. This will allow developers to easily monitor and improve the overall test coverage for the project.

**Describe alternatives you've considered**
As an alternative, I have considered adding the total test coverage to the project README file. However, this solution would not be as easily accessible as an icon on the project dashboard.

Python API

The following example shows how to use Shell Craft inside of your own Python code. The example loads your api key from an environment variable, uses the Bash prompt, and gets input from the user.

import os

from shell_craft import Service
from shell_craft.prompts import BASH_PROMPT

Server(
    api_key = os.environ.get("OPENAI_API_KEY"),
    prompt = BASH_PROMPT,
).query(
    message = input("Enter your request: ")
)

API Key

Shell Craft uses the OpenAI API to generate the shell commands. You will need to create an account with OpenAI and get an API key. Once you have your API key, you can pass it to Shell Craft via command line argument, environment variable, or config file.

Command Line Argument:

shell_craft prompt_type "human_request" --api-key API_KEY

Where prompt_type is the type of prompt you want to use, such as bash, powershell, or feature_request. human_request is the human readable request you want to convert to a shell command. API_KEY is your OpenAI API key.

Environment Variable:

export OPENAI_API_KEY=<your secret key>
shell_craft bash "list all files in directory"

Configuration file - config.json:

{
    "openai_api_key": "<your secret key>"
}

License

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

Acknowledgments

Acknowledgments contain a few of the people who have helped the project along the way.

  • OpenAI for their language models and API.
  • Joel Fourhman for the initial idea, the challenge, and the project name.
  • Chase Montgomery for testing, feedback, and estimated time savings vs manual implementation.
  • Bryan Gonzalez for powershell feedback and merge reviews.
  • Aaron Croissette for business use case feedback and a lovely PyPi icon on the readme.

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

openai_shell_craft-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

openai_shell_craft-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file openai_shell_craft-0.1.0.tar.gz.

File metadata

  • Download URL: openai_shell_craft-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for openai_shell_craft-0.1.0.tar.gz
Algorithm Hash digest
SHA256 db001bf36c81f90aeb73714724b8c1a4a95128946bacec88fa8affae00582e4a
MD5 08de7af4f8bf87a4ddc6eaeaa6a70d03
BLAKE2b-256 b461be10d4f0bc2093fc2090f110e6088ec1d34fc52577c7d10c8e1dc9c21004

See more details on using hashes here.

File details

Details for the file openai_shell_craft-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_shell_craft-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bfe6acb19f9168b8efd7964323b065021f478b415bbf0abc86eadd2d935c0e7
MD5 649e60e42834a433748b966c16ea5806
BLAKE2b-256 54be069d6853471565c624a6e25085a6379842d7e2ed7cbab168609f94c0e426

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page