-
-
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.
This file contains 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 | |
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