Skip to content

Instantly share code, notes, and snippets.

@pan-long
Created September 6, 2018 13:41
Show Gist options
  • Save pan-long/beb29b84f2bf9230117a505276b4058c to your computer and use it in GitHub Desktop.
Save pan-long/beb29b84f2bf9230117a505276b4058c to your computer and use it in GitHub Desktop.
## Setup
# * Create a room with yourself
# * Add a Webhook. Click 'Configure Webhook' in dropdown of your room name. Add a webhook and copy the URL.
# * Put the webhook URL into <Chat Webhook URL> in the code. Copy the code to
# .bashrc
## Usage:
# ```
# sleep 3; hc
# ```
# In case you forgot to add `; hc` at the end, you can still:
# 1. ctrl + z to suspend the running command
# 2. run `fg ; hc` which will bring it back to foreground and add `; hc`
function hc {
STATUS="$([[ $? = 0 ]] && echo 'Succeeded' || echo 'Failed')"
HANGOUTS_CHAT_WEBHOOK_URL='Chat Webhook URL'
COMMAND="$(history|tail -n1|sed -e 's/^\s*[0-9]\+\s*//;s/[;&|]\s*xm$//')"
curl -s -d "{'text':'$STATUS: $COMMAND'}" -H 'Content-Type: application/json;charset=UTF-8' -X POST "$HANGOUTS_CHAT_WEBHOOK_URL" > /dev/null 2>&1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment