Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- # This script shows a countdown timer of 3 different values.
- # It starts with a 25 minute countdown ($work countdown)
- # At the end of 25 minutes notify-send is called to
- # alert you that it's break time. A new countdown timer
- # is started based on whether it's a long break or a
- # short break.
- # The type of break is determined by how many breaks
- # have been taken. Every 4th break is 15min, otherwise
- # it's 5min.
- # https://en.wikipedia.org/wiki/Pomodoro_Technique
- use Modern::Perl;
- use IPC::System::Simple qw( systemx );
- my $work_countdown = 25*60; # in seconds
- my $short_countdown = 5*60;
- my $long_countdown = 15*60;
- my $break_tracker = 1;
- $| = 1; # This ensures the countdown gets updated every second.
- while (1) {
- countdown($work_countdown);
- if ($break_tracker % 4) {
- systemx('notify-send', 'long-break');
- countdown($long_countdown);
- }
- else {
- systemx('notify-send', 'short-break');
- countdown($short_countdown);
- }
- systemx('notify-send', 'back_to_work');
- $break_tracker++;
- }
- # This sub was adapted from code found at
- # https://stackoverflow.com/questions/25835958/perl-countdown
- sub countdown {
- my ($sec) = @_;
- my $beginTime = time;
- my $endTime = $beginTime + $sec;
- for (;;) {
- my $time = time;
- last if ($time >= $endTime);
- printf("\r%02d:%02d:%02d",
- 0,
- ($endTime - $time) / 60 % ($sec),
- ($endTime - $time) % 60,
- );
- sleep(1);
- }
- }
- exit(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement