Skip to content

Instantly share code, notes, and snippets.

@whoward
Last active July 11, 2018 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whoward/b706ab6e1ec748d5dc2040a6adeabd24 to your computer and use it in GitHub Desktop.
Save whoward/b706ab6e1ec748d5dc2040a6adeabd24 to your computer and use it in GitHub Desktop.
simple slack + sqlite pomodoro tracker. Meant to be used in conjunction with https://github.com/whoward/time-tracker. Requires the slack-cli from https://github.com/rockymadden/slack-cli to be on the PATH.
#!/bin/bash
set -e
DURATION=${1:-1800}
START=$(date "+%Y-%m-%d %H:%M:%S.000")
START_SECONDS=$(date "+%s")
UNTIL=$(gdate "+%I:%M%p" --date "+ $DURATION seconds")
function update_slack_status() {
echo "Updating your slack status..."
slack status edit --text "Pomodoro until $UNTIL" --emoji :tomato: > /dev/null
slack snooze start $(($DURATION/60)) > /dev/null
}
function clear_slack_status() {
echo "updating your slack status"
# clear slack status, become active, clear snooze
slack status clear > /dev/null
slack snooze end > /dev/null
}
function wait_duration() {
echo "Starting a pomodoro for $DURATION seconds ($UNTIL)..."
sleep $DURATION
echo -e "\033[0;107m\033[1;91mYour pomodoro is complete!\033[0m"
say "Your pomodoro is complete!"
}
function record_entry() {
FINISH=$(date "+%Y-%m-%d %H:%M:%S.000")
FINISH_SECONDS=$(date "+%s")
ACTUAL_DURATION=$(($FINISH_SECONDS - $START_SECONDS))
SQL="insert into entries values(\"pomodoro\", \"$START\", \"$FINISH\", $ACTUAL_DURATION);"
echo $SQL
sqlite3 $HOME/.time-tracker.db "$SQL"
}
function ctrl_c() {
echo "Aborting pomodoro..."
record_entry
clear_slack_status
exit 0
}
update_slack_status
trap ctrl_c SIGINT
wait_duration
record_entry
clear_slack_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment