Skip to content

Instantly share code, notes, and snippets.

@dasm
Created November 20, 2019 01:48
Show Gist options
  • Save dasm/6fa8f8e4025227fabf40c8313139fcc5 to your computer and use it in GitHub Desktop.
Save dasm/6fa8f8e4025227fabf40c8313139fcc5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Based on Kiailandi (https://github.com/kiailandi)
set -e
minutes=${1:-25}
countdown() {
seconds=$1
date=$((`date +%s` +$seconds));
echo $2: `date`
while [ "$date" -gt `date +%s` ]; do
echo -ne "$(date -u -j -f %s $(($date - `date +%s`)) +%H:%M:%S)\r";
sleep 1
done
afplay /System/Library/Sounds/Funk.aiff
osascript >/dev/null << EOF
display dialog "Stop $2." with title "$2" buttons {"OK"}
EOF
}
# Check os and behave accordingly
if [ "$(uname)" == "Darwin" ]; then
while true; do
countdown $(echo $minutes | awk -F: '{ print ($1 * 60) }') "Work :"
countdown $(echo $minutes | awk -F: '{ print ($1 * 12) }') "Break:"
done
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
while true; do
date1=$((`date +%s` + $wseconds));
while [ "$date1" -ge `date +%s` ]; do
echo -ne "$(date -u --date @$(($date1 - `date +%s` )) +%H:%M:%S)\r";
done
notify-send "Break" "Time to walk and rest";
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
date2=$((`date +%s` + $pseconds));
while [ "$date2" -ge `date +%s` ]; do
echo -ne "$(date -u --date @$(($date2 - `date +%s` )) +%H:%M:%S)\r";
done
notify-send "Work" "Time to get back to work";
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
done
else
echo -ne "Your OS is currently not supported\n";
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment