cleaned up bashisms
This commit is contained in:
@@ -15,7 +15,7 @@ while true; do
|
|||||||
slist="$(nl -nln -w1 -s' - ' "$SPFILE")"
|
slist="$(nl -nln -w1 -s' - ' "$SPFILE")"
|
||||||
sname="$(printf '%s\nNew\nQuit\n' "$slist" | grep . | fzf --tac --footer="$FTR")"
|
sname="$(printf '%s\nNew\nQuit\n' "$slist" | grep . | fzf --tac --footer="$FTR")"
|
||||||
[ "$sname" = 'Quit' ] && break
|
[ "$sname" = 'Quit' ] && break
|
||||||
[ "$sname" = 'New' ] && read -r -p 'New session name: ' sname
|
[ "$sname" = 'New' ] && printf 'New session name: ' && read -r sname
|
||||||
sname="$(echo "$sname" | sed -E 's/^[0-9]+\ -\ //')"
|
sname="$(echo "$sname" | sed -E 's/^[0-9]+\ -\ //')"
|
||||||
if [ -n "$sname" ]; then
|
if [ -n "$sname" ]; then
|
||||||
expect -c "spawn abduco -A \"$sname\" $SHELL; send \"\014\"; interact"
|
expect -c "spawn abduco -A \"$sname\" $SHELL; send \"\014\"; interact"
|
||||||
|
|||||||
@@ -86,9 +86,9 @@ cmd_upload() {
|
|||||||
|
|
||||||
# delete individual remote files
|
# delete individual remote files
|
||||||
cmd_delete() {
|
cmd_delete() {
|
||||||
echo -n 'Confirm file deletion (y to confirm)? ';
|
printf 'Confirm file deletion (y to confirm)? ';
|
||||||
read -r resp
|
read -r resp
|
||||||
if [ "$resp" == "y" ]; then
|
if [ "$resp" = "y" ]; then
|
||||||
$REQCMD -H "$AUTH_HDR" -d "filenames[]=$1" ${APIROOT}/delete
|
$REQCMD -H "$AUTH_HDR" -d "filenames[]=$1" ${APIROOT}/delete
|
||||||
else
|
else
|
||||||
echo 'Operation cancelled'
|
echo 'Operation cancelled'
|
||||||
@@ -103,7 +103,7 @@ cmd_sync() {
|
|||||||
projdir="$1"
|
projdir="$1"
|
||||||
[ -z "$1" ] && projdir="$(pwd)"
|
[ -z "$1" ] && projdir="$(pwd)"
|
||||||
# iterate over the project directory
|
# iterate over the project directory
|
||||||
find "$projdir" \( ! -path '*/.*' \) -type f -printf '%P\n' | while read -r f; do
|
(cd "$projdir" && find . \( ! -path '*/.*' \) -type f | sed 's|^\./||') | while read -r f; do
|
||||||
fullpath=$(realpath "${projdir}/$f")
|
fullpath=$(realpath "${projdir}/$f")
|
||||||
cursha="$(sha1sum -b "$fullpath" | cut -f 1 -d ' ')"
|
cursha="$(sha1sum -b "$fullpath" | cut -f 1 -d ' ')"
|
||||||
prevsha="$(printf '%s' "$flist" | jq -r --arg p "$f" '.[$p]')"
|
prevsha="$(printf '%s' "$flist" | jq -r --arg p "$f" '.[$p]')"
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ while true; do
|
|||||||
slist="$(nl -nln -w1 -s' - ' "$SPFILE")"
|
slist="$(nl -nln -w1 -s' - ' "$SPFILE")"
|
||||||
sname="$(printf '%s\nNew\nQuit\n' "$slist" | grep . | fzf --tac --footer="$FTR")"
|
sname="$(printf '%s\nNew\nQuit\n' "$slist" | grep . | fzf --tac --footer="$FTR")"
|
||||||
[ "$sname" = 'Quit' ] && printf '\033[0m' && break
|
[ "$sname" = 'Quit' ] && printf '\033[0m' && break
|
||||||
[ "$sname" = 'New' ] && read -r -p 'New session name: ' sname
|
[ "$sname" = 'New' ] && printf 'New session name: ' && read -r sname
|
||||||
sname="$(echo "$sname" | sed -E 's/^[0-9]+\ -\ //')"
|
sname="$(echo "$sname" | sed -E 's/^[0-9]+\ -\ //')"
|
||||||
[ -n "$sname" ] && printf '\033[0m' && dtach -A "$SDIR/$sname" $SHELL
|
[ -n "$sname" ] && printf '\033[0m' && dtach -A "$SDIR/$sname" $SHELL
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
# do_task() { # accepts workflow name into $1 and all input into $2
|
# do_task() { # accepts workflow name into $1 and all input into $2
|
||||||
# # your actions here
|
# # your actions here
|
||||||
# }
|
# }
|
||||||
# run-task
|
# run_task
|
||||||
#
|
#
|
||||||
# You can call different workflows from inside tasks by referring to
|
# You can call different workflows from inside tasks by referring to
|
||||||
# this very script using the $SFLIB environment variable or by calling
|
# this very script using the $SFLIB environment variable or by calling
|
||||||
@@ -39,7 +39,7 @@ debugout() { printf '%s\n' "$*" >&2; }
|
|||||||
flowout() { printf '%s\t%s' "$1" "$2"; }
|
flowout() { printf '%s\t%s' "$1" "$2"; }
|
||||||
|
|
||||||
# use this in all task definitions
|
# use this in all task definitions
|
||||||
run-task() {
|
run_task() {
|
||||||
input="$(cat)"
|
input="$(cat)"
|
||||||
wf="$(printf '%s' "$input" | cut -f 1)"
|
wf="$(printf '%s' "$input" | cut -f 1)"
|
||||||
body="$(printf '%s' "$input" | cut -f 2-)"
|
body="$(printf '%s' "$input" | cut -f 2-)"
|
||||||
@@ -57,4 +57,4 @@ sfrun() {
|
|||||||
flowout $wfbase "$(cat)" | SFLIB="$SFLIB" WFDIR="$WFDIR" $SHELL $wfbase | cut -f 2-
|
flowout $wfbase "$(cat)" | SFLIB="$SFLIB" WFDIR="$WFDIR" $SHELL $wfbase | cut -f 2-
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "$(basename "$0")" == "flow.sh" ] && sfrun $*
|
[ "$(basename "$0")" = "flow.sh" ] && sfrun "$@"
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ case "$PARAM" in
|
|||||||
help
|
help
|
||||||
;;
|
;;
|
||||||
"newsrv") # set up Git user on the server
|
"newsrv") # set up Git user on the server
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
$SSHCMD "useradd ${GITUSR}; passwd ${GITUSR}; mkdir -p /home/${GITUSR}/.ssh; echo 'no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty' > /home/${GITUSR}/.ssh/authorized_keys; chown -R ${GITUSR} /home/${GITUSR}/.ssh"
|
$SSHCMD "useradd ${GITUSR}; passwd ${GITUSR}; mkdir -p /home/${GITUSR}/.ssh; echo 'no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty' > /home/${GITUSR}/.ssh/authorized_keys; chown -R ${GITUSR} /home/${GITUSR}/.ssh"
|
||||||
echo "Now, you'll need to enter the newly created ${GITUSR} user password:"
|
echo "Now, you'll need to enter the newly created ${GITUSR} user password:"
|
||||||
ssh-copy-id ${GITUSR}@${THOST}
|
ssh-copy-id ${GITUSR}@${THOST}
|
||||||
@@ -70,18 +70,18 @@ case "$PARAM" in
|
|||||||
echo "Git user set up on ${THOST}. Now use $0 newrepo ${GITUSR}@${THOST} [name] to set up new Git repos"
|
echo "Git user set up on ${THOST}. Now use $0 newrepo ${GITUSR}@${THOST} [name] to set up new Git repos"
|
||||||
;;
|
;;
|
||||||
"newrepo") # set up a new Git repo
|
"newrepo") # set up a new Git repo
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
REPONAME="$3"
|
REPONAME="$3"
|
||||||
[[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1
|
[ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1
|
||||||
REPODIR="${REPONAME}.git"
|
REPODIR="${REPONAME}.git"
|
||||||
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
||||||
$SSHCMD "mkdir -p $FULLREPODIR;cd $FULLREPODIR;git init --bare --shared;chown -R ${GITUSR}:${GITUSR} ."
|
$SSHCMD "mkdir -p $FULLREPODIR;cd $FULLREPODIR;git init --bare --shared;chown -R ${GITUSR}:${GITUSR} ."
|
||||||
echo "Empty repository created at ${USERHOST}:${REPODIR}"
|
echo "Empty repository created at ${USERHOST}:${REPODIR}"
|
||||||
;;
|
;;
|
||||||
"set-repo-desc") # set the repo description for some services
|
"set-repo-desc") # set the repo description for some services
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
REPONAME="$3"
|
REPONAME="$3"
|
||||||
[[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1
|
[ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1
|
||||||
VALUE="$4" # it may be empty
|
VALUE="$4" # it may be empty
|
||||||
REPODIR="${REPONAME}.git"
|
REPODIR="${REPONAME}.git"
|
||||||
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
||||||
@@ -89,9 +89,9 @@ case "$PARAM" in
|
|||||||
echo "Description set for ${REPODIR}"
|
echo "Description set for ${REPODIR}"
|
||||||
;;
|
;;
|
||||||
"set-repo-url") # set the repo clone URL for some services
|
"set-repo-url") # set the repo clone URL for some services
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
REPONAME="$3"
|
REPONAME="$3"
|
||||||
[[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1
|
[ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1
|
||||||
VALUE="$4" # it may be empty
|
VALUE="$4" # it may be empty
|
||||||
REPODIR="${REPONAME}.git"
|
REPODIR="${REPONAME}.git"
|
||||||
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
||||||
@@ -99,9 +99,9 @@ case "$PARAM" in
|
|||||||
echo "Clone URL set for ${REPODIR}"
|
echo "Clone URL set for ${REPODIR}"
|
||||||
;;
|
;;
|
||||||
"set-repo-owner") # set the repo owner name for some services
|
"set-repo-owner") # set the repo owner name for some services
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
REPONAME="$3"
|
REPONAME="$3"
|
||||||
[[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1
|
[ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1
|
||||||
VALUE="$4" # it may be empty
|
VALUE="$4" # it may be empty
|
||||||
REPODIR="${REPONAME}.git"
|
REPODIR="${REPONAME}.git"
|
||||||
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
FULLREPODIR="/home/${GITUSR}/$REPODIR"
|
||||||
@@ -109,7 +109,7 @@ case "$PARAM" in
|
|||||||
echo "Owner name set for ${REPODIR}"
|
echo "Owner name set for ${REPODIR}"
|
||||||
;;
|
;;
|
||||||
"gitd-sd") # set up the Git daemon using a systemd unit
|
"gitd-sd") # set up the Git daemon using a systemd unit
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
TMPUNIT="/tmp/git-daemon.service"
|
TMPUNIT="/tmp/git-daemon.service"
|
||||||
cat << EOF > $TMPUNIT
|
cat << EOF > $TMPUNIT
|
||||||
[Unit]
|
[Unit]
|
||||||
@@ -134,18 +134,18 @@ EOF
|
|||||||
rm -f $TMPUNIT
|
rm -f $TMPUNIT
|
||||||
;;
|
;;
|
||||||
"gitd-publish") # make a repository public via the Git daemon
|
"gitd-publish") # make a repository public via the Git daemon
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
REPONAME="$3"
|
REPONAME="$3"
|
||||||
[[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1
|
[ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1
|
||||||
REPODIR="${REPONAME}.git"
|
REPODIR="${REPONAME}.git"
|
||||||
ACCFILE="/home/${GITUSR}/${REPODIR}/git-daemon-export-ok"
|
ACCFILE="/home/${GITUSR}/${REPODIR}/git-daemon-export-ok"
|
||||||
$SSHCMD "touch $ACCFILE; chown $GITUSR $ACCFILE"
|
$SSHCMD "touch $ACCFILE; chown $GITUSR $ACCFILE"
|
||||||
echo "Repository git://${THOST}/$REPODIR made public"
|
echo "Repository git://${THOST}/$REPODIR made public"
|
||||||
;;
|
;;
|
||||||
"gitd-unpublish") # revoke repository publishing via the Git daemon
|
"gitd-unpublish") # revoke repository publishing via the Git daemon
|
||||||
[[ -z "$USERHOST" ]] && echo "Error: no user and hostname!" && exit 1
|
[ -z "$USERHOST" ] && echo "Error: no user and hostname!" && exit 1
|
||||||
REPONAME="$3"
|
REPONAME="$3"
|
||||||
[[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1
|
[ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1
|
||||||
REPODIR="${REPONAME}.git"
|
REPODIR="${REPONAME}.git"
|
||||||
ACCFILE="/home/${GITUSR}/${REPODIR}/git-daemon-export-ok"
|
ACCFILE="/home/${GITUSR}/${REPODIR}/git-daemon-export-ok"
|
||||||
$SSHCMD "rm -f $ACCFILE"
|
$SSHCMD "rm -f $ACCFILE"
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ f2p() {
|
|||||||
printf '%b' "$cprefix" # always start with the prefix
|
printf '%b' "$cprefix" # always start with the prefix
|
||||||
IFS='' # separator
|
IFS='' # separator
|
||||||
while read -r -s -d '' -n1 b; do # convert every byte
|
while read -r -s -d '' -n1 b; do # convert every byte
|
||||||
if [ "$c" == "$l" ]; then # roll over and output suffix+prefix
|
if [ "$c" = "$l" ]; then # roll over and output suffix+prefix
|
||||||
c=0 # reinit counter
|
c=0 # reinit counter
|
||||||
printf '%b' "$csuffix" # end the chunk
|
printf '%b' "$csuffix" # end the chunk
|
||||||
printf '%b' "$cprefix" # begin a new chunk
|
printf '%b' "$cprefix" # begin a new chunk
|
||||||
@@ -36,13 +36,13 @@ f2p() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# main code
|
# main code
|
||||||
LF=$'\n' # cache the linefeed character
|
LF="$(printf '\n')" # cache the linefeed character
|
||||||
flist='' # pre-build the file list from args
|
flist='' # pre-build the file list from args
|
||||||
dlist='' # pre-build the directory list from args
|
dlist='' # pre-build the directory list from args
|
||||||
for i; do # iterate over args
|
for i; do # iterate over args
|
||||||
bname="${i##*/}" # get the basename
|
bname="${i##*/}" # get the basename
|
||||||
if [ -d "$i" ]; then # it's a directory, we skip . and ..
|
if [ -d "$i" ]; then # it's a directory, we skip . and ..
|
||||||
[ "$bname" == '.' ] || [ "$bname" == '..' ] && continue
|
[ "$bname" = '.' ] || [ "$bname" = '..' ] && continue
|
||||||
dlist="${dlist}${i%/}${LF}" # append the directory
|
dlist="${dlist}${i%/}${LF}" # append the directory
|
||||||
else # it's a file
|
else # it's a file
|
||||||
dname="${i%%$bname}" # get the basedir
|
dname="${i%%$bname}" # get the basedir
|
||||||
|
|||||||
+1
-1
@@ -19,7 +19,7 @@ pngize_raw() {
|
|||||||
# 2. body (raw file data)
|
# 2. body (raw file data)
|
||||||
cat "$1" >> $temp_ppm
|
cat "$1" >> $temp_ppm
|
||||||
# 3. trailing zero bytes
|
# 3. trailing zero bytes
|
||||||
for i in $(seq 1 $remlen); do printf '\x00' >> $temp_ppm; done
|
for i in $(seq 1 $remlen); do printf '\000' >> $temp_ppm; done
|
||||||
# convert PPM to PNG and remove the temporary PPM
|
# convert PPM to PNG and remove the temporary PPM
|
||||||
magick ppm:$temp_ppm png:$ofile
|
magick ppm:$temp_ppm png:$ofile
|
||||||
rm -f $temp_ppm
|
rm -f $temp_ppm
|
||||||
|
|||||||
+4
-4
@@ -27,7 +27,7 @@ if [ "$PROV" = "gh" ]; then
|
|||||||
LANG_URL=""
|
LANG_URL=""
|
||||||
elif [ "$PROV" = "gl" ]; then
|
elif [ "$PROV" = "gl" ]; then
|
||||||
TGT="${temp#*gitlab.com/}"
|
TGT="${temp#*gitlab.com/}"
|
||||||
ROOT_URL="https://gitlab.com/api/v4/projects/${TGT/\//%2F}"
|
ROOT_URL="https://gitlab.com/api/v4/projects/$(echo "$TGT" | sed 's/\//%2F/g')"
|
||||||
LANG_URL="${ROOT_URL}/languages"
|
LANG_URL="${ROOT_URL}/languages"
|
||||||
elif [ "$PROV" = "cb" ]; then
|
elif [ "$PROV" = "cb" ]; then
|
||||||
TGT="${temp#*codeberg.org/}"
|
TGT="${temp#*codeberg.org/}"
|
||||||
@@ -55,15 +55,15 @@ echo "$langdata" | grep -qi "$CHLANG" && CORR_SCORE=$((CORR_SCORE + 10))
|
|||||||
# but if it is the main one, we further increase the score by 50
|
# but if it is the main one, we further increase the score by 50
|
||||||
echo "$mainlang" | grep -qi "$CHLANG" && CORR_SCORE=$((CORR_SCORE + 50))
|
echo "$mainlang" | grep -qi "$CHLANG" && CORR_SCORE=$((CORR_SCORE + 50))
|
||||||
|
|
||||||
if ((CORR_SCORE >= 50)); then
|
if [ "$CORR_SCORE" -ge 50 ]; then
|
||||||
echo "The project $TGT is most likely written in $CHLANG."
|
echo "The project $TGT is most likely written in $CHLANG."
|
||||||
if ((CORR_SCORE >= 100)); then
|
if [ "$CORR_SCORE" -ge 100 ]; then
|
||||||
echo 'The author is a definite fanatic of this language.'
|
echo 'The author is a definite fanatic of this language.'
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
else
|
else
|
||||||
echo "The project $TGT does not seem to be written in $CHLANG."
|
echo "The project $TGT does not seem to be written in $CHLANG."
|
||||||
if ((CORR_SCORE > 0)); then
|
if [ "$CORR_SCORE" -gt 0 ]; then
|
||||||
echo 'However, this language may be partially used there.'
|
echo 'However, this language may be partially used there.'
|
||||||
fi
|
fi
|
||||||
exit 1;
|
exit 1;
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ addhistory() {
|
|||||||
mv ${histfile}.new $histfile
|
mv ${histfile}.new $histfile
|
||||||
}
|
}
|
||||||
|
|
||||||
prompt() { printf "\e[1;32m>> \e[0m"; }
|
prompt() { printf "\033[1;32m>> \033[0m"; }
|
||||||
clearhist() {
|
clearhist() {
|
||||||
printf '[]' > $histfile
|
printf '[]' > $histfile
|
||||||
addhistory system "$SHEESH_SYSPROMPT"
|
addhistory system "$SHEESH_SYSPROMPT"
|
||||||
@@ -30,12 +30,12 @@ setsys() {
|
|||||||
SHEESH_SYSPROMPT="$*"
|
SHEESH_SYSPROMPT="$*"
|
||||||
clearhist
|
clearhist
|
||||||
}
|
}
|
||||||
setsysfile() { setsys "$(<"$1")"; }
|
setsysfile() { setsys "$(cat "$1")"; }
|
||||||
addfile() {
|
addfile() {
|
||||||
tmp="$(mktemp -t furrfufile.XXXXXXX)"
|
tmp="$(mktemp -t furrfufile.XXXXXXX)"
|
||||||
fname="$(basename $1)"
|
fname="$(basename $1)"
|
||||||
if startswith "$1" "http*://"; then
|
if startswith "$1" "http*://"; then
|
||||||
[ -z "$fname" || "$fname" == "/" ] && $fname="${1//\//_}"
|
[ -z "$fname" ] || [ "$fname" = "/" ] && fname="$(echo "$1" | tr '/' '_')"
|
||||||
curl -sSLN $1 > $tmp
|
curl -sSLN $1 > $tmp
|
||||||
else
|
else
|
||||||
cp "$1" $tmp
|
cp "$1" $tmp
|
||||||
@@ -62,15 +62,15 @@ listmodels() {
|
|||||||
${OPENAI_API_KEY:+-H "Authorization: Bearer $OPENAI_API_KEY"} \
|
${OPENAI_API_KEY:+-H "Authorization: Bearer $OPENAI_API_KEY"} \
|
||||||
${SHEESH_COOKIES:+-H "Cookie: $SHEESH_COOKIES"} \
|
${SHEESH_COOKIES:+-H "Cookie: $SHEESH_COOKIES"} \
|
||||||
| jq -r '.data[].id' | while read -r modelname; do
|
| 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
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
help() {
|
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 'Model: %s\n' "$SHEESH_MODEL"
|
||||||
printf 'Temperature: %.2f\n' "$SHEESH_TEMP"
|
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 'Available commands:'
|
||||||
echo
|
echo
|
||||||
echo '* /models: list available models'
|
echo '* /models: list available models'
|
||||||
@@ -97,7 +97,7 @@ help() {
|
|||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
trap cleanup SIGINT SIGABRT SIGHUP SIGQUIT
|
trap cleanup INT ABRT HUP QUIT
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm $histfile $datafile
|
rm $histfile $datafile
|
||||||
printf '\nBye!\n'
|
printf '\nBye!\n'
|
||||||
@@ -106,19 +106,19 @@ cleanup() {
|
|||||||
|
|
||||||
hdrline='----------------------'
|
hdrline='----------------------'
|
||||||
title='SHEE.SH v2 by Luxferre'
|
title='SHEE.SH v2 by Luxferre'
|
||||||
printf '\e[1;36m%s\n%s\n%s\e[0m\n' "$hdrline" "$title" "$hdrline"
|
printf '\033[1;36m%s\n%s\n%s\033[0m\n' "$hdrline" "$title" "$hdrline"
|
||||||
printf '\e[2;37mEndpoint: %s\n' "$SHEESH_API_ROOT"
|
printf '\033[2;37mEndpoint: %s\n' "$SHEESH_API_ROOT"
|
||||||
printf 'Model: %s\n' "$SHEESH_MODEL"
|
printf 'Model: %s\n' "$SHEESH_MODEL"
|
||||||
printf 'Temperature: %.2f\n' "$SHEESH_TEMP"
|
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"
|
setsys "$SHEESH_SYSPROMPT"
|
||||||
while prompt && read -r line; do
|
while prompt && read -r line; do
|
||||||
[ -z "$line" ] && continue
|
[ -z "$line" ] && continue
|
||||||
[ "$line" == "/bye" ] && break
|
[ "$line" = "/bye" ] && break
|
||||||
[ "$line" == "/clear" ] && clearhist && echo "Session cleared" && continue
|
[ "$line" = "/clear" ] && clearhist && echo "Session cleared" && continue
|
||||||
[ "$line" == "/help" ] && help && continue
|
[ "$line" = "/help" ] && help && continue
|
||||||
[ "$line" == "/models" ] && listmodels && continue
|
[ "$line" = "/models" ] && listmodels && continue
|
||||||
startswith "$line" '/sys ' && setsys "${line#\/sys }" && echo "System prompt set and session cleared" && 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" '/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
|
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
|
while IFS= read -r chunk; do
|
||||||
[ -z "$chunk" ] && continue
|
[ -z "$chunk" ] && continue
|
||||||
data="${chunk#data: }"
|
data="${chunk#data: }"
|
||||||
[ "$data" == "[DONE]" ] && break
|
[ "$data" = "[DONE]" ] && break
|
||||||
delta=''
|
delta=''
|
||||||
startswith "$data" '{' && delta="$(printf '%s' "$data" | jq -rj '.choices[0].delta.content // empty' 2>/dev/null;printf x)"
|
startswith "$data" '{' && delta="$(printf '%s' "$data" | jq -rj '.choices[0].delta.content // empty' 2>/dev/null;printf x)"
|
||||||
delta="${delta%?}"
|
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"
|
tailbuf="$tailbuf$delta"
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
|
|||||||
Reference in New Issue
Block a user