Skip to content

Instantly share code, notes, and snippets.

@dulldesk
Last active January 19, 2023 06:00
Show Gist options
  • Save dulldesk/95060d14da1238d6eed9676b8d215d24 to your computer and use it in GitHub Desktop.
Save dulldesk/95060d14da1238d6eed9676b8d215d24 to your computer and use it in GitHub Desktop.
PowerShell Pomodoro timer
function Start-Pomodoro {
param(
[int]$work=20,
[int]$break1=5,
[int]$break2=15,
[Alias("Silent")][switch]$mute=$false
)
$yellow = "Yellow"; if ($env:WT_SESSION) {$yellow = "DarkYellow"}
clear
$beep = {}; if (-not $mute) {$beep = {[console]::beep((random -min 400 -max 1350),400)}}
$pomo = {Start-Countdown -min $work -col $yellow; . $beep}
$break = {param($m=($break1)) Start-Countdown -min $m -col Blue; . $beep}
# iterations of work + short break before a long break
$itr = 2
while ($True) {
for ($i=0; $i -lt $itr; $i++) {
. $pomo
. $break
}
. $pomo
. $break $break2
}
}
function Start-Countdown {
param(
[Parameter(Mandatory=$True)][int]$mins,
[Parameter()][Alias("color","clr")]$colour=([console]::foregroundcolor)
)
$pom = New-Timespan -min $mins
$sec = New-Timespan -sec 1
for (; $pom -ne (New-Timespan); $pom -= $sec) {
Write-Host "`r$pom" -NoNewline -fore $colour
sleep 1
}
Write-Host ""
}
Set-Alias -name Pomodoro -value Start-Pomodoro
Set-Alias -name Pomo -value Start-Pomodoro

Basic usage:

. .\pomodoro.ps1
Start-Pomodoro
Start-Pomodoro -Work 25 -Mute

Optional parameters:

  • -Work [int] length (minutes) of the work period
  • -Break1 [int] length (minutes) of the short break
  • -Break2 [int] length (minutes) of the long break
  • -Mute disables the beep between periods. Alias: -Silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment