From 7489e042c607a809bb8a7d934388c2de51fe0e33 Mon Sep 17 00:00:00 2001 From: EnigmaCurry Date: Sat, 22 Jun 2024 00:56:28 -0600 Subject: [PATCH] matrix markdown --- config/bash/alias.sh | 2 ++ config/bash/matrix.sh | 21 ++++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config/bash/alias.sh b/config/bash/alias.sh index 2f3edc7..a7f688e 100644 --- a/config/bash/alias.sh +++ b/config/bash/alias.sh @@ -5,3 +5,5 @@ alias ls='ls --color=auto' alias grep='grep --color=auto' alias bb='rlwrap bb' alias ec="${HOME}/git/vendor/enigmacurry/emacs/ec" + +vars() { set -o posix; set | cut -d= -f1 | column; } diff --git a/config/bash/matrix.sh b/config/bash/matrix.sh index b60cfcf..182c9b9 100644 --- a/config/bash/matrix.sh +++ b/config/bash/matrix.sh @@ -4,6 +4,10 @@ ## https://matrix-org.github.io/matrix-hookshot/latest/hookshot.html ## https://github.com/spantaleev/matrix-docker-ansible-deploy/blob/master/docs/configuring-playbook-bridge-hookshot.md +## Put these required config vars into your ~/.bashrc.local : +## MATRIX_ALERT_WEBHOOK=https://matrix.enigmacurry.com/hookshot/webhooks/XXXXXXX +## BCT_ACTION_COMMAND='matrix-send "Command completed on ${HOSTNAME} :: ${output_str}"' + matrix-alert() { if [[ -n "${MATRIX_ALERT_WEBHOOK}" ]]; then curl -X POST "${MATRIX_ALERT_WEBHOOK}" --json '{"text":"'"$*"'"}' >/dev/null 2>&1 @@ -13,6 +17,17 @@ matrix-alert() { fi } -## Put this in your ~/.bashrc.local : -## MATRIX_ALERT_WEBHOOK=https://matrix.enigmacurry.com/hookshot/webhooks/XXXXXXX -## BCT_ACTION_COMMAND='matrix-send "Command completed on ${HOSTNAME} :: ${output_str}"' +matrix-markdown() { + local MARKDOWN_FILE=$1; + if [[ ! -f "${MARKDOWN_FILE}" ]]; then + echo "Markdown file does not exist: ${MARKDOWN_FILE}" >/dev/stderr + return 1 + fi + if [[ -z "${MATRIX_ALERT_WEBHOOK}" ]]; then + echo "Missing MATRIX_ALERT_WEBHOOK env var." >/dev/stderr + return 1 + else + curl -X POST "${MATRIX_ALERT_WEBHOOK}" --json "$(echo "{}" | jq -c --rawfile md $1 '.text=$md')" >/dev/null 2>&1 + fi +} +