Please
20. 1. 2025https://gist.github.com/pmarreck/9ce17f7996347dd532f3e20a2a383c0d
“please”- a bash function to ask an LLM to compose and run a bash command, with an approval/denial step All it needs is an OPENAI_API_KEY
context: https://news.ycombinator.com/item?id=42695547
I like this function:
needs() {
command -v "$1" > /dev/null || { >&2 printf "%s is required- not installed or in PATH; %s\n" "$1" "${@:2}"; return 1; }
}
which according to chatgpt could be even nicer:
needs() {
if ! command -v "$1" > /dev/null; then
>&2 printf "%s is required but not installed or not in PATH. %s\n" "$1" "${@:2}"
return 1
fi
}