Skip to content

Instantly share code, notes, and snippets.

@withinboredom
Created May 26, 2017 17:31
Show Gist options
  • Save withinboredom/809acb291ba5d9382481898f3191b842 to your computer and use it in GitHub Desktop.
Save withinboredom/809acb291ba5d9382481898f3191b842 to your computer and use it in GitHub Desktop.
Standup
#!/bin/bash
# Slack API token
token="YOUR_TOKEN_HERE"
postMessageUrl="https://slack.com/api/chat.postMessage"
defaultChannel="#SOME_DEFAULT_CHANNEL"
# Was last time "Yesterday"?
echo "Yesterday? Or some other day? (Empty for yesterday)"
read lastTime
echo -en "\033[1A\033[2K"
! [[ $lastTime =~ ^\s*$ ]] || lastTime="Yesterday"
yesterdayTemp=$"# What did you do $lastTime? (Write empty file to abort)
"
todayTemp=$'# What are you going to do today? (Write empty file to abort)
'
# Open yesterday template in Vim
echo "$yesterdayTemp" > ~/.standup
vim -c "set ft=gitcommit" +2 ~/.standup
yesterday=$(sed -e '/^#/ d' -e 's/"/\\"/g' < ~/.standup)
rm ~/.standup
if [[ $yesterday =~ ^\s*$ ]] ;then
echo "Aborted due to empty standup."
exit 0
fi
# Open today template in Vim
echo "$todayTemp" > ~/.standup
vim -c "set ft=gitcommit" +2 ~/.standup
today=$(sed -e '/^#/ d' -e 's/"/\\"/g' < ~/.standup)
rm ~/.standup
if [[ $today =~ ^\s*$ ]] ;then
echo "Aborted due to empty standup."
exit 0
fi
# Save backup just in case
echo $"# Yesterday
$yesterday
# Today
$today" > ~/.standup_bak
echo "Enter a channel to post in (empty for '$defaultChannel'): "
read channel
echo -en "\033[1A\033[2K"
if [[ $channel =~ ^\ *$ ]] ;then
channel="$defaultChannel"
fi
attachments=$"[{
\"title\": \"Standup\",
\"fields\": [{
\"title\": \"$lastTime\",
\"value\": \"$yesterday\"
},
{
\"title\": \"Today\",
\"value\": \"$today\"
}],
\"color\": \"#b2ff59\",
\"mrkdwn_in\": [\"fields\"],
\"fallback\": \"*$lastTime*: $yesterday *Today: $today\"
}]"
# Send the request
curl --data-urlencode "token=$token" \
--data-urlencode "channel=$channel" \
--data-urlencode "as_user=true" \
--data-urlencode "link_names=1" \
--data-urlencode "attachments=$attachments" \
"$postMessageUrl"
echo "Standup submitted to channel $channel."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment