60 lines
2.1 KiB
Markdown
60 lines
2.1 KiB
Markdown
# OpenAI API / ChatGPT bash integration
|
|
|
|
The script `runai_alias.sh` can be used to provide the `runai` command in bash. The command enabled you to generate commands directly in your terminal.
|
|
|
|
## Requirements
|
|
|
|
This script only requires Python 3.7+ and the `openai` Python package to be installed.
|
|
|
|
Install Python and Pip on Debian/Ubuntu: `sudo apt install python3 python3-pip`
|
|
Install Python and Pip on CentOS/RHEL-based: `sudo yum install epel-release && sudo yum install python3-pip`
|
|
Install Python and Pip on ArchLinux: `sudo pacman -Sy && sudo pacman -S python-pip`
|
|
Install Python and Pip in Fedora: `sudo dnf install python3-pip`
|
|
Install via pip: `pip install openai`
|
|
|
|
## Installing as alias command
|
|
|
|
**Note:** To keep the alias command working, the script must remain at the same location after setting the alias command.
|
|
|
|
Install the alias command using `./runai.sh -a`
|
|
|
|
## Example Usage as Script
|
|
|
|
```bash
|
|
user@host:~$ ./runai.sh scan my primary local network for online hosts
|
|
The generated command is:
|
|
nmap -sn $(ip route | awk '/default/ {print $3}' | awk -F. '{print $1"."$2"."$3".0/24"}')
|
|
|
|
Do you want to execute the command? [Y/n]: y
|
|
|
|
...
|
|
```
|
|
|
|
You always have the choice whether the command shall be executed or not, unless you pass `-y` as first parameter. When the command is executed, you can also access it later using your history.
|
|
|
|
## Example Usage as Alias
|
|
|
|
```bash
|
|
user@host:~$ ./runai scan my primary local network for online hosts
|
|
The generated command is:
|
|
nmap -sn $(ip route | awk '/default/ {print $3}' | awk -F. '{print $1"."$2"."$3".0/24"}')
|
|
|
|
Do you want to execute the command? [Y/n]: y
|
|
|
|
...
|
|
```
|
|
|
|
## Example Usage with ALL_YES set
|
|
|
|
**WARNING:** Allowing the script to just execute the generated command can be potentially dangerous. Use with care!
|
|
|
|
```bash
|
|
user@host:~$ ./runai -a scan my primary local network for online hosts
|
|
Running the command without asking for confirmation!
|
|
Running the command:
|
|
nmap -sn $(ip route | awk '/default/ {print $3}' | awk -F. '{print $1"."$2"."$3".0/24"}')
|
|
|
|
...
|
|
```
|
|
|
|
**NOTE** that you should *never* provide any sensitive data with your prompt! |