bashGPT
is a command-line tool that converts plain English descriptions into valid bash commands using OpenAI's GPT-3.5-turbo model. It ensures that only syntactically valid bash commands are generated, offering a convenient way to perform common system operations through natural language.
- Convert English to Bash: Translate natural language descriptions into valid bash commands.
- Syntax Validation: Automatically checks that the generated commands are valid bash syntax.
- User Confirmation: Prompts the user to confirm before executing the generated command.
- Error Handling: Exits gracefully if the input cannot be converted to a valid bash command.
- Bash: This tool is written in bash and requires a Unix-like environment (Linux, macOS, WSL on Windows).
- OpenAI API Key: You need an API key from OpenAI to use this tool.
-
Clone the Repository:
git clone https://github.com/madhunimmo/bashGPT.git cd bashGPT
-
Set Up the API Key:
You can set the OpenAI API key as an environment variable:
export OPENAI_API_KEY="your-openai-api-key"
Alternatively, you can add this line to your
.bashrc
or.zshrc
to make it persistent:echo 'export OPENAI_API_KEY="your-openai-api-key"' >> ~/.bashrc source ~/.bashrc
-
Make the Script Executable:
chmod +x bashGPT.sh
You can use bashGPT
by either passing the plain English description as an argument or entering it interactively.
./bashGPT.sh "list all files in the current directory"
./bashGPT.sh
Please enter a command in plain English:
> list all files in the current directory
Bash command generated: ls
Do you want to execute this command? [y/N]: y
If the command is valid and the user confirms, the tool will execute the command.
If the input cannot be converted into a valid bash command, bashGPT
will return an error and exit:
Error: No valid bash command was generated.
If you'd like to contribute to this project, feel free to fork the repository and submit a pull request. Any suggestions, bug reports, or improvements are welcome!
This project is licensed under the MIT License. See the LICENSE file for more details.
This tool leverages OpenAI's GPT-3.5-turbo model for natural language processing and the jq
tool for JSON manipulation. Special thanks to OpenAI for providing the API and the community for developing open-source tools like jq
.