Created
May 6, 2020 15:34
-
-
Save sverrejoh/bc61211c8445a20917fc1464c2b282d2 to your computer and use it in GitHub Desktop.
Function for sending a notification from shell
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
| function tellme() { | |
| # The success value from the previous command (have to keep it or | |
| # it'll be overwritten by the equation below) | |
| local previous=$? | |
| local statusMessage | |
| [[ $previous -eq 0 ]] \ | |
| && statusMessage="Success" \ | |
| || statusMessage="Failure" | |
| # Prefix message with status | |
| message="$statusMessage: $@"; | |
| # Say the result to the speaker and ... | |
| say $message | |
| # Send a notification to my phone. | |
| local token=INSERT_YOUR_TOKEN | |
| local user=INSERT_YOUR_USER | |
| curl -s \ | |
| -F "token=$token" \ | |
| -F "user=$user" \ | |
| -F "title=$statusMessage" \ | |
| -F "message=$message" \ | |
| https://api.pushover.net/1/messages.json | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment