ChatBash is a Bash script that interacts with OpenAI's GPT models to generate and execute shell commands based on user input. It ensures that dangerous commands are identified and prompts the user for confirmation before execution.
Before using ChatBash, make sure you have the following installed on your system:
- Bash (Tested on Bash 4.4+)
- curl
- jq
You can install the required dependencies using the following command:
sudo apt-get update && sudo apt-get install -y curl jq-
Clone the repository:
git clone https://github.com/trackzero/chatbash.git cd chatbash -
Set up your OpenAI API Key:
Export your OpenAI API key as an environment variable:
export OPENAI_API_KEY="your-api-key-here"
Alternatively, you can add the above line to your
.bashrcor.bash_profileto persist the environment variable across sessions. -
Make the script executable:
chmod +x chatbash
Run the script with a description of what you want to accomplish:
./chatbash "Description of the task you want to accomplish"Alternatively, you can run the script without any arguments, and it will prompt you for a description:
./chatbashThe script will generate shell commands based on the provided description using OpenAI's GPT4o model. It will then display the commands and ask for your confirmation before executing them.
./chatbash.sh "List all files in the current directory and count them"Fine, you want to make it executable as a regular shell command?
sudo ln -s ~/chatbash/chatbash /usr/local/bin/chatbash #adjust source directory as appropriate.- The script checks for potentially dangerous commands (e.g.,
rm -rf,mkfs, etc.) and warns the user before executing them. - It prompts the user for confirmation before executing any commands.
- I'm pretty lazy when it comes to error checking and safety features so there's probably a lot I missed. Use at your own risk. Make backups first. You're on your own if you break something. And for the love of whatever gods you prefer, do not run this on prod systems.
ChatBashDev:~$ chatbash "Can you tell me what version of linux Im running, what version of python is installed, and what version of node is installed?"
Commands to be executed:
uname -a
python --version
node --version
Do you want to execute these commands? (yes/no): yes
Executing commands...
Running: uname -a
Linux genai 6.8.8-2-pve #1 SMP PREEMPT_DYNAMIC PMX 6.8.8-2 (2024-06-24T09:00Z) x86_64 x86_64 x86_64 GNU/Linux
Running: python --version
Python 3.12.4
Running: node --version
/usr/local/bin/chatbash: line 106: node: command not found
Error: Command 'node --version' failed with status 127.
Execution will continue with the next command.
Yeah yeah, I know. There's a Bedrock version, too. That's the chatbash-br version.
But there's some twists. You'll need two environment variables:
export BEDROCK_API_KEY="your-key-here"
export BEDROCK_API_URL="http://<your-bedrock-access-gateway-url-here>/api/v1"Well, there's one over here: https://github.com/aws-samples/bedrock-access-gateway
Setup of the gateway is beyond the scope of this readme. Could I have done it natively? Probably. Did I? Well, obviously not.