Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d5f1acf

Browse files
committed
Update pomodoro script to work both on linux and macOS
1 parent 545ecfc commit d5f1acf

File tree

1 file changed

+36
-16
lines changed

1 file changed

+36
-16
lines changed

scripts/pomodoro.sh

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,40 @@
55
# The second argument is the break length.
66
# Made by Kiailandi (https://github.com/kiailandi)
77

8-
wseconds=${1:-25}*60
9-
pseconds=${2:-wseconds/300}*60
8+
wseconds=${1:-25}*60;
9+
pseconds=${2:-wseconds/300}*60;
1010

11-
while true; do
12-
date1=$(($(date +%s) + $wseconds))
13-
while [ "$date1" -ge $(date +%s) ]; do
14-
echo -ne "$(date -u --date @$(($date1 - $(date +%s))) +%H:%M:%S)\r"
15-
done
16-
notify-send "Break" "Time to walk and rest"
17-
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
18-
date2=$(($(date +%s) + $pseconds))
19-
while [ "$date2" -ge $(date +%s) ]; do
20-
echo -ne "$(date -u --date @$(($date2 - $(date +%s))) +%H:%M:%S)\r"
21-
done
22-
notify-send "Work" "Time to get back to work"
23-
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n'
24-
done
11+
# Check os and behave accordingly
12+
if [ "$(uname)" == "Darwin" ]; then
13+
while true; do
14+
date1=$((`date +%s` + $wseconds));
15+
while [ "$date1" -ge `date +%s` ]; do
16+
echo -ne "$(date -u -j -f %s $(($date1 - `date +%s`)) +%H:%M:%S)\r";
17+
done
18+
osascript -e 'display notification "Time to walk and rest!" with title "Break"';
19+
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
20+
date2=$((`date +%s` + $pseconds));
21+
while [ "$date2" -gt `date +%s` ]; do
22+
echo -ne "$(date -u -j -f %s $(($date2 - `date +%s`)) +%H:%M:%S)\r";
23+
done
24+
osascript -e 'display notification "Time to get back to work" with title "Work"';
25+
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
26+
done
27+
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
28+
while true; do
29+
date1=$((`date +%s` + $wseconds));
30+
while [ "$date1" -ge `date +%s` ]; do
31+
echo -ne "$(date -u --date @$(($date1 - `date +%s` )) +%H:%M:%S)\r";
32+
done
33+
notify-send "Break" "Time to walk and rest";
34+
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
35+
date2=$((`date +%s` + $pseconds));
36+
while [ "$date2" -ge `date +%s` ]; do
37+
echo -ne "$(date -u --date @$(($date2 - `date +%s` )) +%H:%M:%S)\r";
38+
done
39+
notify-send "Work" "Time to get back to work";
40+
read -n1 -rsp $'Press any key to continue or Ctrl+C to exit...\n';
41+
done
42+
else
43+
echo -ne "Your OS is currently not supported\n";
44+
fi

0 commit comments

Comments
 (0)