smartsh/README.md

49 lines
1.7 KiB
Markdown
Raw Normal View History

2023-04-10 07:04:51 +00:00
<h1>smartsh.py</h1>
*smartsh.py* is a simple python script that I wrote which can take a task description (any string) as argument and query OpenAPI's API to tell you how to accomplish the given task using a shell command. Yes, chatgpt from command line (sort of). But let me tell you a simple trick that you can use to supercharge your bash with it!
2023-04-09 17:23:46 +00:00
bash (I think starting from 4.0) conveniently provides a handler for situations when a command that the user entered is invalid.
You just need to provide a function named command_not_found_handle () and point it to the action to be taken on, yes, when a command is not found :-)
In this case, you need to add the following to your .bashrc for the magic to work:
2023-04-09 15:43:18 +00:00
```
export OPENAI_API_KEY="your_api_key"
2023-04-09 17:23:46 +00:00
export SMARTSH_PATH="path_where_you_checked_out_smartsh"
2023-04-09 15:43:18 +00:00
command_not_found_handle () {
echo "Let's get help from OpenAI API!"
python3 $SMARTSH_PATH/smartsh.py "$@"
}
2023-04-09 17:23:46 +00:00
```
Some examples:
```
bash$ Show the most recent file in the present working directory
Let's get help from OpenAI API!
ls -t | head -n1
```
```
bash$ Kill all Google chrome renderer processes
Let's get help from OpenAI API!
The command to accomplish this task is:
pkill -f "chrome.*renderer"
This command uses the `pkill` command to send a signal to all processes whose name matches the regular expression `chrome.*renderer`. This will effectively kill all Google Chrome renderer processes.
2023-04-09 15:43:18 +00:00
```
You can set the following additional environment variables which smartsh can make use of:
2023-04-10 06:28:56 +00:00
`OPENAI_MODEL_ID`: The model to use: Supported models are "text-davinci-003", "gpt-3.5-turbo"
If the variable is not set, we use "gpt-3.5-turbo" by default
2023-04-10 06:28:56 +00:00
`SMARTSH_DEBUG` : Will print additional debug info when running smartsh