diff --git a/stdin2discord.bash b/stdin2discord.bash index 1a7b5ca..c99e9ac 100644 --- a/stdin2discord.bash +++ b/stdin2discord.bash @@ -1,29 +1,29 @@ -#!/bin/bash -set -e - -send() { - local _msg=$1 - if [[ -z $_msg ]]; then - return - fi - - curl -X POST \ - -H "Content-Type: application/json" \ - -d "{\"content\":\"\`\`\`diff\n$_msg\`\`\`\"}" \ - "$DISCORD_WEBHOOK" -} - -msg="" - -while IFS= read -r line; do - line="$(sed 's@"@\\"@g' <<< "$line")" # Json screening - len="$(wc -m <<< "$msg$line")" - if [[ $len -ge 1985 ]]; then - send "$msg" - msg="$line" - else - msg+="$line\\n" - fi -done - -send "$msg" +#!/bin/bash +set -ex + +send() { + local _msg=$1 + if [[ -z $_msg ]]; then + return + fi + + curl -X POST \ + -H "Content-Type: application/json" \ + -d "{\"content\":\"\`\`\`diff\n$_msg\`\`\`\"}" \ + "$DISCORD_WEBHOOK" +} + +msg="" + +while IFS= read -r line; do + line="$(sed 's@"@\\"@g' <<< "$line")" # Json screening + len="$(wc -m <<< "$msg$line")" + if [[ $len -ge 1985 ]]; then + send "$msg" + msg="$line" + else + msg+="$line\\n" + fi +done + +send "$msg"