-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsuggestbash
More file actions
executable file
·58 lines (53 loc) · 1.94 KB
/
suggestbash
File metadata and controls
executable file
·58 lines (53 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
if [ "$#" -eq 0 ] || [ "$1" = "--help" ]; then
echo "Usage: $(basename $0) [options] [task description]"
echo ""
echo "Options:"
echo " --help Show this help message and exit"
echo ""
echo "Description:"
echo " This script sends a task description to ChatGPT, which returns a bash"
echo " command line for the given task and prints it."
exit 0
fi
machinedescription="For a $(sysctl -n hw.model) with $(sysctl -n hw.machine) architecture running $(sw_vers -productName) $(sw_vers -productVersion) ,"
# prints a tool description that can be used by the AI to check the path for programs
function checkactiondescription() {
cat<<EOF
[
{
"function": {
"name": "checkpath",
"description": "Can be used to check which tools exist in the path. Only the first 100 tools are returned - please limit by using the prefix and / or the regex parameter.",
"parameters": {
"type": "object",
"properties": {
"prefix": {
"type": "string",
"description": "The prefix to check for. If empty, all tools in the path are returned. This argument prefix is given to 'compgen -c \$prefix'."
},
"regex": {
"type": "string",
"description": "An egrep regular expression to match the returned tool names. If empty, no additional filter is applied"
}
},
"required": [ "prefix", "regex" ],
"additionalProperties": false
},
"strict": true
},
"commandline": [
"bash", "-c", "compgen -c '\$prefix' | egrep '\$regex' | head -n 100"
],
"stdin": ""
}
]
EOF
}
function sysmessage() {
cat<<EOF
$machinedescription write a bash command line including explanation, or answer a question.
Check whether optional tools are in the path with the checkpath tool, and give installation instructions if they are not.
EOF
}
exec chatgpt -m gpt-4o -tf <(checkactiondescription) -s "$(sysmessage)" "$@"