cleaned up bashisms

This commit is contained in:
Luxferre
2026-07-27 20:33:44 +03:00
parent 3c952b7631
commit 9775b3edc4
9 changed files with 46 additions and 46 deletions
+16 -16
View File
@@ -20,7 +20,7 @@ addhistory() {
mv ${histfile}.new $histfile
}
prompt() { printf "\e[1;32m>> \e[0m"; }
prompt() { printf "\033[1;32m>> \033[0m"; }
clearhist() {
printf '[]' > $histfile
addhistory system "$SHEESH_SYSPROMPT"
@@ -30,12 +30,12 @@ setsys() {
SHEESH_SYSPROMPT="$*"
clearhist
}
setsysfile() { setsys "$(<"$1")"; }
setsysfile() { setsys "$(cat "$1")"; }
addfile() {
tmp="$(mktemp -t furrfufile.XXXXXXX)"
fname="$(basename $1)"
if startswith "$1" "http*://"; then
[ -z "$fname" || "$fname" == "/" ] && $fname="${1//\//_}"
[ -z "$fname" ] || [ "$fname" = "/" ] && fname="$(echo "$1" | tr '/' '_')"
curl -sSLN $1 > $tmp
else
cp "$1" $tmp
@@ -62,15 +62,15 @@ listmodels() {
${OPENAI_API_KEY:+-H "Authorization: Bearer $OPENAI_API_KEY"} \
${SHEESH_COOKIES:+-H "Cookie: $SHEESH_COOKIES"} \
| jq -r '.data[].id' | while read -r modelname; do
printf '\e[0;36m* %s\e[0m\n' "$modelname"
printf '\033[0;36m* %s\033[0m\n' "$modelname"
done
}
help() {
printf 'Current settings:\n\n\e[2;37mEndpoint: %s\n' "$SHEESH_API_ROOT"
printf 'Current settings:\n\n\033[2;37mEndpoint: %s\n' "$SHEESH_API_ROOT"
printf 'Model: %s\n' "$SHEESH_MODEL"
printf 'Temperature: %.2f\n' "$SHEESH_TEMP"
printf 'System prompt: "%s"\e[0m\n\n' "$SHEESH_SYSPROMPT"
printf 'System prompt: "%s"\033[0m\n\n' "$SHEESH_SYSPROMPT"
echo 'Available commands:'
echo
echo '* /models: list available models'
@@ -97,7 +97,7 @@ help() {
echo
}
trap cleanup SIGINT SIGABRT SIGHUP SIGQUIT
trap cleanup INT ABRT HUP QUIT
cleanup() {
rm $histfile $datafile
printf '\nBye!\n'
@@ -106,19 +106,19 @@ cleanup() {
hdrline='----------------------'
title='SHEE.SH v2 by Luxferre'
printf '\e[1;36m%s\n%s\n%s\e[0m\n' "$hdrline" "$title" "$hdrline"
printf '\e[2;37mEndpoint: %s\n' "$SHEESH_API_ROOT"
printf '\033[1;36m%s\n%s\n%s\033[0m\n' "$hdrline" "$title" "$hdrline"
printf '\033[2;37mEndpoint: %s\n' "$SHEESH_API_ROOT"
printf 'Model: %s\n' "$SHEESH_MODEL"
printf 'Temperature: %.2f\n' "$SHEESH_TEMP"
printf '\e[1;36m%s\e[0m\n' "$hdrline"
printf '\033[1;36m%s\033[0m\n' "$hdrline"
setsys "$SHEESH_SYSPROMPT"
while prompt && read -r line; do
[ -z "$line" ] && continue
[ "$line" == "/bye" ] && break
[ "$line" == "/clear" ] && clearhist && echo "Session cleared" && continue
[ "$line" == "/help" ] && help && continue
[ "$line" == "/models" ] && listmodels && continue
[ "$line" = "/bye" ] && break
[ "$line" = "/clear" ] && clearhist && echo "Session cleared" && continue
[ "$line" = "/help" ] && help && continue
[ "$line" = "/models" ] && listmodels && continue
startswith "$line" '/sys ' && setsys "${line#\/sys }" && echo "System prompt set and session cleared" && continue
startswith "$line" '/sysload ' && setsysfile "${line#\/sysload }" && echo "System prompt loaded and session cleared" && continue
startswith "$line" '/temp ' && SHEESH_TEMP="${line#\/temp }" && echo "Temperature set to $SHEESH_TEMP" && continue
@@ -147,11 +147,11 @@ while prompt && read -r line; do
while IFS= read -r chunk; do
[ -z "$chunk" ] && continue
data="${chunk#data: }"
[ "$data" == "[DONE]" ] && break
[ "$data" = "[DONE]" ] && break
delta=''
startswith "$data" '{' && delta="$(printf '%s' "$data" | jq -rj '.choices[0].delta.content // empty' 2>/dev/null;printf x)"
delta="${delta%?}"
[ -n "$delta" ] && printf "\e[0;33m%s\e[0m" "$delta"
[ -n "$delta" ] && printf "\033[0;33m%s\033[0m" "$delta"
tailbuf="$tailbuf$delta"
done
echo