-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathfindprogram
More file actions
executable file
·71 lines (60 loc) · 2.32 KB
/
findprogram
File metadata and controls
executable file
·71 lines (60 loc) · 2.32 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
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
if [ "$#" -eq 0 ] || [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ "$1" = "-?" ]; then cat <<EOF
Usage: $(basename $0) {program description}
Searches in the PATH for programs that do what the description says.
EOF
exit 0
fi
description="$*"
machinedescription="For a $(sysctl -n hw.model) with $(sysctl -n hw.machine) architecture running $(sw_vers -productName) $(sw_vers -productVersion) ,"
listprompt=$(cat <<EOF
$machinedescription
print an extensive long list of program names that might be useful for fulfilling the following task but might be not installed.
Include many possible alternatives. Use glob patterns to account for variability - like foo* for programs starting with foo.
For MacOS, include homebrew installable programs.
A script will then look whether there are any such programs in the PATH and the Applications folders and tell you the
matches, so that you can make a program later that fulfills the task. Print only the program names, no descriptions, as JSON.
The task is:
$description
EOF
)
programs=$(chatgpt -p "$listprompt" -rf <(cat <<EOF
{
"type": "object",
"properties": {
"programs": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": ["programs"],
"additionalProperties": false
}
EOF
) | jq -r '.programs[]')
echo "Looking for relevant programs..."
# echo $programs
foundprograms=$(
for program in $programs; do
(IFS=:; for dir in $PATH; do
for file in "$dir"/$program; do
if [ -x "$file" ]; then
echo "$(basename $file)"
fi
done
done)
(for dir in /System/Applications/ /Applications/ $HOME/Applications/; do
for file in "$dir"/$program.app; do
if [ -x "$file" ]; then
echo "$(basename $file)"
fi
done
done)
done
)
# echo "Found programs: $foundprograms"
echo "Asking ChatGPT..."
# exec chatgpt -4 -s "$machinedescription write a bash command line including explanation, or answer a question. The following programs have been verified to be available for that, so are recommended if appropriate: $foundprograms." "$description"
exec chatgpt -4 -s "$machinedescription Suggest several programs that fulfill the task the user wants to do, with a short description. The following programs have been verified to be available for that, so are recommended if appropriate: $foundprograms." "$description"