Skip to main content

ShellGenius is a tool to generate shell commands from description in natural language.

Project description

ShellGenius

ShellGenius is an intuitive CLI tool designed to enhance your command-line experience by turning your task descriptions into efficient shell commands.

Powered by OpenAI's gpt-3.5-turbo AI model, ShellGenius generates accurate commands based on your input and provides step-by-step explanations to help you understand the underlying logic.

Table of Contents

  1. Video Demos
    1. Video Frames Extraction
    2. Directory Synchronization
    3. Find and Copy Files with Keywords
  2. Installation
    1. Install via pipx (recommended)
    2. OpenAI API key
  3. Usage
    1. Regarding the Quotes
    2. Creating an Alias
    3. Make ShellGenius Respond in Your Native Language
  4. Examples
    1. Remove Duplicate Lines
    2. Extract Columns in a File
    3. Download a File
    4. Number of Lines in a File
  5. Limitations
  6. License

Video Demos

Video Frames Extraction

https://github.com/sderev/shellgenius/assets/24412384/509ee15a-9804-41ad-ba31-3fdf02fc627f

Directory Synchronization

https://github.com/sderev/shellgenius/assets/24412384/c9ad7560-cde3-4c68-aa89-b9bc4c9303f7

Find and Copy Files with Keywords

shellgenius_3

Installation

Ensure you have Python 3.8 or later installed on your system. To install ShellGenius, use the following command:

python3 -m pip install shellgenius

Install via pipx (recommended)

pipx is an alternative package manager for Python applications. It allows you to install and run Python applications in isolated environments, preventing conflicts between dependencies and ensuring that each application uses its own set of packages. I recommend using pipx to install ShellGenius.

First, install pipx if you haven't already:

  • On macOS and Linux:

    python3 -m pip install --user pipx
    python3 -m pipx ensurepath
    

Alternatively, you can use your package manager (brew, apt, etc.).

  • On Windows:

    py -m pip install --user pipx
    py -m pipx ensurepath
    

Once pipx is installed, you can install ShellGenius using the following command:

pipx install shellgenius

OpenAI API key

ShellGenius requires an OpenAI API key to function. You can obtain a key by signing up for an account at OpenAI's website.

Once you have your API key, set it as an environment variable:

  • On macOS and Linux:

    export OPENAI_API_KEY="your-api-key-here"
    

    To avoid having to type it everyday, you can create a file with the key:

    echo "your-api-key" > ~/.openai-api-key.txt
    

    Note: Remember to replace "your-api-key" with your actual API key.

    And then, you can add this to your shell configuration file (.bashrc, .zshrc, etc.):

    export OPENAI_API_KEY="$(cat ~/.openai-api-key.txt)"
    
  • On Windows:

    setx OPENAI_API_KEY your_key
    

Usage

To use ShellGenius, simply type shellgenius followed by a description of the task you want to perform:

shellgenius "description of your task"

The tool will generate a shell command based on your description, display it with an explanation, and prompt you to confirm if you want to execute the command.

Regarding the Quotes

The quotes are not necessary when the task description does not contain a single quote, or a special character.

Not necessary:

shellgenius compile and run myprogramm.cpp

Necessary:

shellgenius "find and replace 'oldtext' with 'newtext' in *.txt files"

Creating an Alias

To further enhance the usability of ShellGenius, even with the presence of autocompletion, I recommend to create an alias for effortless access. One suggested alias is ??.

By defining an alias, you can invoke ShellGenius simply by typing ?? followed by your task description, eliminating the need to type the full command each time.

To create the alias, add the following line to your shell configuration file (~/.bashrc, ~/.bash_profile, or ~/.zshrc, depending on your shell):

alias '??'='shellgenius'

After adding the alias, you can use ShellGenius by typing ?? instead of shellgenius, making your command-line experience even more seamless and efficient.

Note: Make sure to restart your shell or run source ~/.bashrc (or the corresponding file for your shell) for the alias to take effect.

Make ShellGenius Respond in Your Native Language

You can describe your task in your native language, but ShellGenius might still respond in English. If that happens, you can add a specific request at the end of your task description. Here's an example:

shellgenius "Description of your task in your own language. Réponds en français."

In the above command, "Réponds en français" is a request for ShellGenius to respond in French. You can replace this with a similar phrase in your language. For example, if you want the response in German, you can use "Antworte auf Deutsch". ShellGenius will then oblige and respond in the requested language.

shellgenius "Erstellt eine Datei. Antworte auf Deutsch."

Examples

Here are some examples of ShellGenius in action:

Remove Duplicate Lines

shellgenius "remove duplicate lines from file.txt"

Output:

awk '!seen[$0]++' file.txt

Explanation:
* awk is a pattern scanning and processing language
* '!seen[$0]++' is an awk expression that removes duplicate lines
* file.txt is the name of the file to process

Be careful with your answer.
Do you want to execute this command? [Y/n]: y

Extract Columns in a File

shellgenius "extract columns 1, 3, and 5 from data.csv"

Output:

cut -d',' -f1,3,5 data.csv

Explanation:
* cut command is used to extract portions of lines from files
* -d',' specifies the delimiter as a comma
* -f1,3,5 specifies the columns to extract
* data.csv is the input CSV file

Be careful with your answer.
Do you want to execute this command? [Y/n]: y

Download a File

shellgenius "download a file from https://example.com/file.zip"

Output:

curl -OJL https://example.com/file.zip

Explanation:
* curl is a command-line tool for transferring data using various protocols
* -O option saves the downloaded file with its original name
* -J option tries to set the file name based on the URL
* -L option follows redirects if the URL points to a different location
* https://example.com/file.zip is the URL of the file to download

Be careful with your answer.
Do you want to execute this command? [Y/n]: y

Number of Lines in a File

shellgenius "count the number of lines in a file called data.csv"

Output:

wc -l data.csv

Explanation:
* wc is a word, line, and byte count utility
* -l flag counts the number of lines
* data.csv is the target file

Be careful with your answer.
Do you want to execute this command? [Y/n]: y

Limitations

ShellGenius is powered by an AI model and may not always generate the most efficient or accurate commands. Exercise caution when executing commands, especially when working with sensitive data or critical systems.

License

ShellGenius is released under the Apache 2.0 Licence.


https://github.com/sderev/shellgenius

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

ShellGenius-0.1.11.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ShellGenius-0.1.11-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file ShellGenius-0.1.11.tar.gz.

File metadata

  • Download URL: ShellGenius-0.1.11.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ShellGenius-0.1.11.tar.gz
Algorithm Hash digest
SHA256 d747cf9dcd41f1827b25a79a01b292c3db9bf4931fa7dc2eb97cb086c2d1c103
MD5 3b6857185df63dab8eb842caed7625fc
BLAKE2b-256 4ec37b332e7a4f3b57ac373c82e1922cf011321c0d72c5abca05361bade95d09

See more details on using hashes here.

File details

Details for the file ShellGenius-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: ShellGenius-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ShellGenius-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 2413649b447fa57f7ea3fc42901a6f8cf2c46619c0c4f58bd69cd0085354db5a
MD5 3b00944bae112d7bf64f5526d45e1d2d
BLAKE2b-256 8091abe765539d76e2a3b96810f58c3c9572ee4628a71cc7f558724712be626e

See more details on using hashes here.

Supported by

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