Skip to main content

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 <human request>

By default, Shell Craft will atempt to determine the prompt type based on the current shell (Powershell or Bash).

Shell Craft supports many prompt types, such as:
* Bash
* Powershell
* Feature Request

For additional help you can run:

```bash
$ shell-craft --help

Bash Example

$ shell-craft --prompt 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 --prompt 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 --prompt 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

To obtain an API key from the OpenAI platform, follow these steps:

Go to https://platform.openai.com/account/api-keys in your web browser.

Log in to your OpenAI account or create a new account if you don't have one.

Click the "Create new secret key" button.

Copy the key that is generated for you.

Decide how you want to use the key:

Note that API keys are sensitive information and should be kept confidential. Make sure you don't share your API key with anyone who shouldn't have access to it. 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.

Option 1: 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.

Option 2: Environment Variable:

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

Option 3 (Recommended): 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.

Release files for openai-shell-craft 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-shell-craft 0.2.0
File Size Uploaded
openai_shell_craft-0.2.0.tar.gz 8.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-shell-craft 0.2.0
File Interpreter ABI Platform
openai_shell_craft-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 kB

Release files / openai_shell_craft-0.2.0.tar.gz

Download URL openai_shell_craft-0.2.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
79e96d78dbde01f17ef814e800a6e5d2794bd132d04bba432d6beca59498cd81
BLAKE2b-256 checksum
How to use checksums
3d1012538b7665695031079a4fbd2fb6078aa83b9394096e49d610206a1c2528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release files / openai_shell_craft-0.2.0-py3-none-any.whl

Download URL openai_shell_craft-0.2.0-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a4ec29aeca728510dfbd9444718c179bcc318c2c7bc6f159d5ca1db72de5454
BLAKE2b-256 checksum
How to use checksums
e50a58a72dbdd501f23f7a5f820eefcaa2627e21dc05c317e51e6f3e43b48dc3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release history Release notifications | RSS feed

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.4.0

2 release files

0.3.0

2 release files

This release

0.2.0 This release

2 release files

0.1.0

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page