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
~/.gptdoor rungptdoto have it created for you - Create
~/.gptdo/.envwith the following contents:
OPENAI_API_KEY=your-openai-api-key
GPT_MODEL=gpt-4oThe gptdo tool has a couple key limitations:
- Non-persistent shell environment: If gptdo tried to run the commands
cd ~/newdirthentouch new_filein order, it will NOT touchnew_fileinnewdir, but in whatever working directory you rangptdoin, because each command is run in a new subshell. This also means that any changesgptdomakes to your current environment (such as PWD or any other environment variables) will be gone whengptdois done running. - No stdin pipe: If a command that is run by
gptdorequires user input, such as ay/nprompt, 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 accessgptdo -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_dbfile.
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.