diff --git a/abmux.sh b/abmux.sh index 750e0fd..607b86b 100755 --- a/abmux.sh +++ b/abmux.sh @@ -15,7 +15,7 @@ while true; do slist="$(nl -nln -w1 -s' - ' "$SPFILE")" sname="$(printf '%s\nNew\nQuit\n' "$slist" | grep . | fzf --tac --footer="$FTR")" [ "$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]+\ -\ //')" if [ -n "$sname" ]; then expect -c "spawn abduco -A \"$sname\" $SHELL; send \"\014\"; interact" diff --git a/cities.sh b/cities.sh index efd8be1..858d3b1 100755 --- a/cities.sh +++ b/cities.sh @@ -86,9 +86,9 @@ cmd_upload() { # delete individual remote files cmd_delete() { - echo -n 'Confirm file deletion (y to confirm)? '; + printf 'Confirm file deletion (y to confirm)? '; read -r resp - if [ "$resp" == "y" ]; then + if [ "$resp" = "y" ]; then $REQCMD -H "$AUTH_HDR" -d "filenames[]=$1" ${APIROOT}/delete else echo 'Operation cancelled' @@ -103,7 +103,7 @@ cmd_sync() { projdir="$1" [ -z "$1" ] && projdir="$(pwd)" # 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") cursha="$(sha1sum -b "$fullpath" | cut -f 1 -d ' ')" prevsha="$(printf '%s' "$flist" | jq -r --arg p "$f" '.[$p]')" diff --git a/dmux.sh b/dmux.sh index aff3327..01142ab 100755 --- a/dmux.sh +++ b/dmux.sh @@ -17,7 +17,7 @@ while true; do slist="$(nl -nln -w1 -s' - ' "$SPFILE")" sname="$(printf '%s\nNew\nQuit\n' "$slist" | grep . | fzf --tac --footer="$FTR")" [ "$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]+\ -\ //')" [ -n "$sname" ] && printf '\033[0m' && dtach -A "$SDIR/$sname" $SHELL done diff --git a/flow.sh b/flow.sh index 548abc9..bca3b7b 100755 --- a/flow.sh +++ b/flow.sh @@ -22,7 +22,7 @@ # do_task() { # accepts workflow name into $1 and all input into $2 # # your actions here # } -# run-task +# run_task # # You can call different workflows from inside tasks by referring to # 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"; } # use this in all task definitions -run-task() { +run_task() { input="$(cat)" wf="$(printf '%s' "$input" | cut -f 1)" body="$(printf '%s' "$input" | cut -f 2-)" @@ -57,4 +57,4 @@ sfrun() { flowout $wfbase "$(cat)" | SFLIB="$SFLIB" WFDIR="$WFDIR" $SHELL $wfbase | cut -f 2- } -[ "$(basename "$0")" == "flow.sh" ] && sfrun $* +[ "$(basename "$0")" = "flow.sh" ] && sfrun "$@" diff --git a/ghmd.sh b/ghmd.sh index d2ef700..44b14e0 100755 --- a/ghmd.sh +++ b/ghmd.sh @@ -62,7 +62,7 @@ case "$PARAM" in help ;; "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" echo "Now, you'll need to enter the newly created ${GITUSR} user password:" 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" ;; "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" - [[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1 + [ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1 REPODIR="${REPONAME}.git" FULLREPODIR="/home/${GITUSR}/$REPODIR" $SSHCMD "mkdir -p $FULLREPODIR;cd $FULLREPODIR;git init --bare --shared;chown -R ${GITUSR}:${GITUSR} ." echo "Empty repository created at ${USERHOST}:${REPODIR}" ;; "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" - [[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1 + [ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1 VALUE="$4" # it may be empty REPODIR="${REPONAME}.git" FULLREPODIR="/home/${GITUSR}/$REPODIR" @@ -89,9 +89,9 @@ case "$PARAM" in echo "Description set for ${REPODIR}" ;; "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" - [[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1 + [ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1 VALUE="$4" # it may be empty REPODIR="${REPONAME}.git" FULLREPODIR="/home/${GITUSR}/$REPODIR" @@ -99,9 +99,9 @@ case "$PARAM" in echo "Clone URL set for ${REPODIR}" ;; "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" - [[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1 + [ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1 VALUE="$4" # it may be empty REPODIR="${REPONAME}.git" FULLREPODIR="/home/${GITUSR}/$REPODIR" @@ -109,7 +109,7 @@ case "$PARAM" in echo "Owner name set for ${REPODIR}" ;; "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" cat << EOF > $TMPUNIT [Unit] @@ -134,18 +134,18 @@ EOF rm -f $TMPUNIT ;; "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" - [[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1 + [ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1 REPODIR="${REPONAME}.git" ACCFILE="/home/${GITUSR}/${REPODIR}/git-daemon-export-ok" $SSHCMD "touch $ACCFILE; chown $GITUSR $ACCFILE" echo "Repository git://${THOST}/$REPODIR made public" ;; "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" - [[ -z "$REPONAME" ]] && echo "Error: no repository name!" && exit 1 + [ -z "$REPONAME" ] && echo "Error: no repository name!" && exit 1 REPODIR="${REPONAME}.git" ACCFILE="/home/${GITUSR}/${REPODIR}/git-daemon-export-ok" $SSHCMD "rm -f $ACCFILE" diff --git a/lshar.sh b/lshar.sh index 2b178aa..7207962 100644 --- a/lshar.sh +++ b/lshar.sh @@ -16,7 +16,7 @@ f2p() { printf '%b' "$cprefix" # always start with the prefix IFS='' # separator 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 printf '%b' "$csuffix" # end the chunk printf '%b' "$cprefix" # begin a new chunk @@ -36,13 +36,13 @@ f2p() { } # main code -LF=$'\n' # cache the linefeed character +LF="$(printf '\n')" # cache the linefeed character flist='' # pre-build the file list from args dlist='' # pre-build the directory list from args for i; do # iterate over args bname="${i##*/}" # get the basename if [ -d "$i" ]; then # it's a directory, we skip . and .. - [ "$bname" == '.' ] || [ "$bname" == '..' ] && continue + [ "$bname" = '.' ] || [ "$bname" = '..' ] && continue dlist="${dlist}${i%/}${LF}" # append the directory else # it's a file dname="${i%%$bname}" # get the basedir diff --git a/pngizer.sh b/pngizer.sh index 2cd980c..dd3d436 100755 --- a/pngizer.sh +++ b/pngizer.sh @@ -19,7 +19,7 @@ pngize_raw() { # 2. body (raw file data) cat "$1" >> $temp_ppm # 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 magick ppm:$temp_ppm png:$ofile rm -f $temp_ppm diff --git a/rusty-checker.sh b/rusty-checker.sh index 9a33870..dfe4ccf 100755 --- a/rusty-checker.sh +++ b/rusty-checker.sh @@ -27,7 +27,7 @@ if [ "$PROV" = "gh" ]; then LANG_URL="" elif [ "$PROV" = "gl" ]; then 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" elif [ "$PROV" = "cb" ]; then 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 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." - if ((CORR_SCORE >= 100)); then + if [ "$CORR_SCORE" -ge 100 ]; then echo 'The author is a definite fanatic of this language.' fi exit 0 else 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.' fi exit 1; diff --git a/shee.sh b/shee.sh index 665cc8d..8177b04 100755 --- a/shee.sh +++ b/shee.sh @@ -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