A command-line tool which takes instructions in plain english and uses AI to suggest and run terminal commands based on the specified output
- Clone the repository to your desired location
- Create a symlink to bin/gptdo somewhere on your path, e.g.
ln -s ./bin/gptdo /usr/bin/gptdo
- Create directory
~/.gptdo
or rungptdo
to have it created for you - Create
~/.gptdo/.env
with the following contents:
OPENAI_API_KEY=your-openai-api-key
GPT_MODEL=gpt-4o
The gptdo
tool has a couple key limitations:
- Non-persistent shell environment: If gptdo tried to run the commands
cd ~/newdir
thentouch new_file
in order, it will NOT touchnew_file
innewdir
, but in whatever working directory you rangptdo
in, because each command is run in a new subshell. This also means that any changesgptdo
makes to your current environment (such as PWD or any other environment variables) will be gone whengptdo
is done running. - No stdin pipe: If a command that is run by
gptdo
requires user input, such as ay/n
prompt, it will get stuck, as stdin is not currently forwarded to the user.
Use the -p
flag to ask a question directly in your command. This will immediately kick-off the processing of the response, and will apply special formatting to your conversation history like the default gptdo
mode does.
Example:
$> gptdo -p "Give me an interesting fact in 5 words or less"
> Honey never spoils over time.
Use the -y
flag to automatically run any recommended commands without being asked for approval first. Use at your own risk.
You can use gptdo -F file1 file2 file3
to add extra context to the chat. These files can contain anything - it could be a file you want to do some code analysis on, extra prompt instructions that you've saved to a file for ease of re-use, or environment configurations for prompts which require extra knowledge such as a database endpoint.
If a specified file does not exist relative to your current working directory, it will check to see if the file exists within ~/.gptdo/contexts
. If you have some special context you will re-use frequently but don't need for every use of gptdo
, it is recommended to create it as a file in ~/.gptdo/contexts
.
Example:
nano ~/.gptdo/contexts/my_db
- Contents:
MySQL Database Info:
- host: db.myapp.com
- user: remote
- password: prompt for password
- db_name: my_app_db
- notes:
- The remote user for this DB has read-only access
gptdo -F my_db -p "Open a connection to my database"
- GPT will prompt you to run a mysql command which will connect you to the db as laid out in the
my_db
file.
Use the -r
flag in conjuction with -p
to get gptdo's commands as raw output, and omit any other output. This makes it possible to run command directly in your shell using eval
.
Example:
$> eval $(gptdo -r -p "change my directory to my home directory")
- gptdo will print
cd ~
and that will be evaluated, thus moving you to your home directory.