diff --git a/discord-if-distinct.sh b/discord-if-distinct.sh deleted file mode 100755 index d66197e..0000000 --- a/discord-if-distinct.sh +++ /dev/null @@ -1,92 +0,0 @@ -#!/bin/bash - -LOCATION=`dirname "$0"` - -source "${LOCATION}/config.sh" - -if [[ $# -gt 2 ]]; then - HOOK_ARG="$1" - BOBBY="$2" - # sed removes spaces before each line - MESSAGE=`echo "${@:3}" | sed 's/^ *//' | sed 's/ *$//'` -else - BOBBY="$1" - # sed removes spaces before each line - MESSAGE=`echo "${@:2}" | sed 's/^ *//' | sed 's/ *$//'` - - if [[ "$MESSAGE" == "general" ]] || [[ "$MESSAGE" == "block" ]] || [[ "$MESSAGE" == "restake" ]] || [[ "$MESSAGE" == "storage" ]]; then - HOOK_ARG="$MESSAGE" - MESSAGE='' - fi -fi - -if [[ -z "$MESSAGE" ]]; then - echo 'no message provided' - exit 0 -fi - -# sed removes blank lines from the end of the message -FULL_MESSAGE=`echo "${MESSAGE}" | sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'` - -# if message is too long, split it, and after curl, recursively call with remainder -# 2k max, but we must account for escaping text in json, so limit to 90% capacity -EXTRA="${MESSAGE:1800}" - -if [ -n "${EXTRA}" ]; then - MESSAGE="${MESSAGE:0:1800}" - - # as an added elegance, when spliting into pieces, find the last \n newline, - # and break there instead, but only if the new smaller chunk is of sufficient size - chunk1=`echo "$MESSAGE" | head -n -1` - chunks=`echo "$MESSAGE" | tail -n 1` - if (( "${#chunk1}" >= 1000 )); then - MESSAGE="$chunk1" - EXTRA="${chunks}${EXTRA}" - fi -fi - -# sed: rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead -# linux is fine with the missing zero, but discord needs it -MESSAGE=`echo "${MESSAGE}" | jq -aRs . | sed 's/\\\\u001b\[m/\\\\u001b[0m/g'` -HOOK="general" -HOOK_URL=$DISCORD_GENERAL_HOOK - -case $HOOK_ARG in - block) - # force block format without color - if [[ "$MESSAGE" != *"\\u001b"* ]]; then - MESSAGE="\"\`\`\`${MESSAGE:1:-1}\n\`\`\`\"" - # just here to resolve formatting issue in vim "`" - fi - ;; - restake) - HOOK="restake" - HOOK_URL=$DISCORD_RESTAKE_HOOK - ;; - storage) - HOOK="storage" - HOOK_URL=$DISCORD_STORAGE_HOOK - ;; -esac - -# if color detected, update message from "" to "```ansi ```", so it gets displayed correctly -if [[ "$MESSAGE" == *"\\u001b"* ]]; then - MESSAGE="\"\`\`\`ansi\n${MESSAGE:1:-1}\n\`\`\`\"" - # just here to resolve formatting issue in vim "`" -fi - -OLD_MSG="" -if [ -f "${LOCATION}/distinct/${BOBBY}.msg" ]; then - OLD_MSG=`cat "${LOCATION}/distinct/${BOBBY}.msg"` -fi - -if [ "${FULL_MESSAGE}" != "${OLD_MSG}" ]; then - echo "${FULL_MESSAGE}" > "${LOCATION}/distinct/${BOBBY}.msg" - - curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id,.message' - - if [ -n "${EXTRA}" ]; then - "${LOCATION}/discord-old.sh" "${HOOK}" "${EXTRA}" - fi -fi - diff --git a/discord-old.sh b/discord-old.sh deleted file mode 100755 index 1f43e10..0000000 --- a/discord-old.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/bash - -LOCATION=`dirname "$0"` - -source "${LOCATION}/config.sh" - -if [[ $# -gt 1 ]]; then - HOOK_ARG="$1" - # sed removes spaces before each line - MESSAGE=`echo "${@:2}" | sed 's/^ *//' | sed 's/ *$//'` -else - # sed removes spaces before each line - MESSAGE=`echo "${@}" | sed 's/^ *//' | sed 's/ *$//'` - - if [[ "$MESSAGE" == "general" ]] || [[ "$MESSAGE" == "block" ]] || [[ "$MESSAGE" == "restake" ]] || [[ "$MESSAGE" == "storage" ]]; then - HOOK_ARG="$MESSAGE" - MESSAGE='' - fi -fi - -if [[ -z "$MESSAGE" ]]; then - echo 'no message provided' - exit 0 -fi - -# if message is too long, split it, and after curl, recursively call with remainder -# 2k max, but we must account for escaping text in json, so limit to 90% capacity -EXTRA="${MESSAGE:1800}" - -if [ -n "${EXTRA}" ]; then - MESSAGE="${MESSAGE:0:1800}" - - # as an added elegance, when spliting into pieces, find the last \n newline, - # and break there instead, but only if the new smaller chunk is of sufficient size - chunk1=`echo "$MESSAGE" | head -n -1` - chunks=`echo "$MESSAGE" | tail -n 1` - if (( "${#chunk1}" >= 1000 )); then - MESSAGE="$chunk1" - EXTRA="${chunks}${EXTRA}" - fi -fi - - -# sed: rewrite json string, because "\u001b[m" needs to "\u001b[0m" instead -# linux is fine with the missing zero, but discord needs it -MESSAGE=`echo "${MESSAGE}" | jq -aRs . | sed 's/\\\\u001b\[m/\\\\u001b[0m/g'` -HOOK="general" -HOOK_URL=$DISCORD_GENERAL_HOOK - -case $HOOK_ARG in - block) - # force block format without color - if [[ "$MESSAGE" != *"\\u001b"* ]]; then - MESSAGE="\"\`\`\`${MESSAGE:1:-1}\n\`\`\`\"" - # just here to resolve formatting issue in vim "`" - fi - ;; - restake) - HOOK="restake" - HOOK_URL=$DISCORD_RESTAKE_HOOK - ;; - storage) - HOOK="storage" - HOOK_URL=$DISCORD_STORAGE_HOOK - ;; -esac - -# if color detected, update message from "" to "```ansi ```", so it gets displayed correctly -if [[ "$MESSAGE" == *"\\u001b"* ]]; then - MESSAGE="\"\`\`\`ansi\n${MESSAGE:1:-1}\n\`\`\`\"" - # just here to resolve formatting issue in vim "`" -fi - -curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DISCORD_SERVER_NAME}\", \"content\": ${MESSAGE}}" $HOOK_URL | jq -r '.id,.message' - -if [ -n "${EXTRA}" ]; then - "${LOCATION}/discord-old.sh" "${HOOK}" "${EXTRA}" -fi - diff --git a/fetch-all.sh b/fetch-all.sh index 42f9664..0ae3a4c 100755 --- a/fetch-all.sh +++ b/fetch-all.sh @@ -36,7 +36,7 @@ fi function process_git_fetch () { startedIn=`pwd` location=$(realpath $(dirname "$@")) - line="--- --- --- --- --- --- --- --- --- ---" + line="--- --- --- --- --- --- --- --- ---" # use "--" to tell printf there are no more commands, only strings to print printf -- "--- git fetch %s %s ---\n" "$location" "${line:${#location}}" cd "$location" diff --git a/list-all.sh b/list-all.sh index f652286..5153518 100755 --- a/list-all.sh +++ b/list-all.sh @@ -36,7 +36,7 @@ fi function process_git_list () { startedIn=`pwd` location=$(realpath $(dirname "$@")) - line="--- --- --- --- --- --- --- --- --- ---" + line="--- --- --- --- --- --- --- --- ---" # use "--" to tell printf there are no more commands, only strings to print printf -- "--- git remote %s %s ---\n" "$location" "${line:${#location}}" cd "$location" diff --git a/pull-all.sh b/pull-all.sh index c96ac37..1a0aa09 100755 --- a/pull-all.sh +++ b/pull-all.sh @@ -36,7 +36,7 @@ fi function process_git_pull () { startedIn=`pwd` location=$(realpath $(dirname "$@")) - line="--- --- --- --- --- --- --- --- --- ---" + line="--- --- --- --- --- --- --- --- ---" # use "--" to tell printf there are no more commands, only strings to print printf -- "--- git pull %s %s ---\n" "$location" "${line:${#location}}" cd "$location" diff --git a/status-all.sh b/status-all.sh index 6948aec..1458068 100755 --- a/status-all.sh +++ b/status-all.sh @@ -36,7 +36,7 @@ fi function process_git_status () { startedIn=$(pwd) location=$(realpath $(dirname "$@")) - line="--- --- --- --- --- --- --- --- --- ---" + line="--- --- --- --- --- --- --- --- ---" # use "--" to tell printf there are no more commands, only strings to print printf -- "--- git status %s %s ---\n" "$location" "${line:${#location}}" cd "$location"