Created
September 13, 2017 04:37
-
-
Save particle4dev/bef0a25d9b40e2491e272cdcc329d627 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Usage: slackpost --text="123" <channel=???> | |
| function slackpost { | |
| for i in "$@" | |
| do | |
| case $i in | |
| -t=*|--text=*) | |
| TEXT="${i#*=}" | |
| shift # past argument=value | |
| ;; | |
| -c=*|--channel=*) | |
| CHANNEL="${i#*=}" | |
| shift # past argument=value | |
| ;; | |
| -u=*|--username=*) | |
| USERNAME="${i#*=}" | |
| shift # past argument=value | |
| ;; | |
| *) | |
| # unknown option | |
| ;; | |
| esac | |
| done | |
| if [ -z $TEXT ]; | |
| then | |
| echo "No text specified" | |
| exit 1 | |
| fi | |
| if [ -z $CHANNEL ]; | |
| then | |
| CHANNEL="announcements" | |
| fi | |
| if [ -z $USERNAME ]; | |
| then | |
| USERNAME="Gitlab" | |
| fi | |
| escapedText=$(echo $TEXT | sed 's/"/\"/g' | sed "s/'/\'/g" ) | |
| json="{\"channel\": \"#$CHANNEL\", \"username\": \"$USERNAME\", \"text\": \"$escapedText\"}" | |
| curl -X POST --data-urlencode "payload=$json" <hooks.slack.com /> | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment