Skip to content

Instantly share code, notes, and snippets.

@ypchen
Last active February 17, 2019 11:40
Show Gist options
  • Select an option

  • Save ypchen/b464cc9ed30e7d66a583d76b38e13809 to your computer and use it in GitHub Desktop.

Select an option

Save ypchen/b464cc9ed30e7d66a583d76b38e13809 to your computer and use it in GitHub Desktop.

Revisions

  1. ypchen revised this gist Feb 17, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion message-to-Slack.bash
    Original file line number Diff line number Diff line change
    @@ -38,4 +38,4 @@ fi

    text="${MSG_PREFIX}${text}${MSG_APPENDIX}"

    curl --insecure -X POST -H 'Content-type: application/json' --data '{"text":"${text}"}' "${webhook_url}"
    curl --insecure -X POST -H 'Content-type: application/json' --data '{"text":"'"${text}"'"}' "${webhook_url}"
  2. ypchen created this gist Feb 17, 2019.
    41 changes: 41 additions & 0 deletions message-to-Slack.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #!/bin/bash

    # default
    if [ -z ${CURL+x} ]; then
    CURL="/usr/bin/curl"
    fi
    if [ -z ${ECHO+x} ]; then
    ECHO="/usr/bin/echo"
    fi
    if [ -z ${CUT+x} ]; then
    CUT="/usr/bin/cut"
    fi

    # webhook_url, MSG_PREFIX, & CURL, ECHO, CUT if necessary
    CONF="${HOME}/.Slack.conf"
    source ${CONF}

    if [ -z ${MSG_PREFIX+x} ]; then
    MSG_PREFIX=""
    fi

    if [ -z ${MSG_APPENDIX+x} ]; then
    MSG_APPENDIX=""
    fi

    if [ -z ${text+x} ]; then
    text="${1}"
    fi

    prefixMode=$(${ECHO} "${text}" | ${CUT} -c 1-4)
    if [ "${prefixMode}" == "YPM0" ]; then
    text=$(${ECHO} "${text}" | ${CUT} -c 5-)
    elif [ "${prefixMode}" == "YPM1" ]; then
    text=$(${ECHO} "${text}" | ${CUT} -c 5-)
    msg=$(eval ${ECHO} "${text}")
    text=$(${ECHO} -e "${msg}")
    fi

    text="${MSG_PREFIX}${text}${MSG_APPENDIX}"

    curl --insecure -X POST -H 'Content-type: application/json' --data '{"text":"${text}"}' "${webhook_url}"