Skip to content

Instantly share code, notes, and snippets.

@txitxo0
Forked from bashbunni/.zshrc
Last active May 20, 2025 07:14
Show Gist options
  • Save txitxo0/5028a3060cd19d347387e23cc862ae91 to your computer and use it in GitHub Desktop.
Save txitxo0/5028a3060cd19d347387e23cc862ae91 to your computer and use it in GitHub Desktop.
CLI Pomodoro for Powershell
function Start-Pomodoro {
param(
[ValidateSet("work", "rest")]
[string]$Mode = "work",
[int]$Minutes = $(if ($Mode -eq "work") { 45 } else { 10 }),
[System.Drawing.Color]$startColor = [System.Drawing.Color]::Aqua,
[System.Drawing.Color]$endColor = [System.Drawing.Color]::MintCream
)
$startTime = Get-Date -Format "hh:mm"
$end = (Get-Date).AddMinutes($Minutes)
$barLength = 30
$totalSeconds = $Minutes * 60
$blockChar = "$([char]0x2588)"
$emptyChar = "$([char]0x2591)"
$initialLeft = [Console]::CursorLeft
$initialTop = [Console]::CursorTop
while ((Get-Date) -lt $end) {
$remaining = $end - (Get-Date)
$elapsed = $totalSeconds - [int]$remaining.TotalSeconds
$percent = [math]::Round(($elapsed / $totalSeconds) * 100)
$filled = [int](($percent / 100) * $barLength)
$bar = ""
for ($i = 0; $i -lt $barLength; $i++) {
if ($i -lt $filled) {
$ratio = $i / $barLength
$r = [int]($startColor.R + ($endColor.R - $startColor.R) * $ratio)
$g = [int]($startColor.G + ($endColor.G - $startColor.G) * $ratio)
$b = [int]($startColor.B + ($endColor.B - $startColor.B) * $ratio)
$bar += "$([char]0x1b)[38;2;${r};${g};${b}m$blockChar$([char]0x1b)[0m"
} else {
$bar += "$([char]0x1b)[38;5;240m$emptyChar$([char]0x1b)[0m"
}
}
$timeLeft = ("{0:mm\:ss}" -f $remaining)
$modeText = if ($Mode -eq "work") {
"We are working"
} else {
"We are resting"
}
[Console]::SetCursorPosition($initialLeft, $initialTop)
[Console]::Write("$bar")
[Console]::Write(" {0}% - {1} [{2} since $startTime]", $percent, $timeLeft, $modeText)
Start-Sleep -Seconds 1
}
if (-not (Get-Module -ListAvailable -Name BurntToast)) {
Install-Module -Name BurntToast -Scope CurrentUser -Force
Import-Module BurntToast -ErrorAction SilentlyContinue
}
$toastText = if ($Mode -eq "work") {
"Pomodoro done. Let's take a break!"
} else {
"Break done, get back to work!"
}
$logoPath = Join-Path $PSScriptRoot "logo.jpg"
if (Test-Path -Path $logoPath) {
New-BurntToastNotification -Text "Pomodoro", $toastText -AppLogo $logoPath
} else {
New-BurntToastNotification -Text "Pomodoro", $toastText
}
}
function work { Start-Pomodoro -Mode "work" -startColor MediumPurple -endColor HotPink }
function rest { Start-Pomodoro -Mode "rest" -startColor LightGreen}
Set-Alias -Name work -Value work
Set-Alias -Name rest -Value rest
Export-ModuleMember -Function Start-Pomodoro, work, rest
@txitxo0
Copy link
Author

txitxo0 commented May 19, 2025

Based on the work of the Pomodoro CLI from bashbunni and, taking in account I use to work in Windows and I don't like to use subsystems like WSL (but I prefer no Windows SO), I dev a simply Pomodoro CLI like for windowsusers.

Pomodoro Timer Script for PowerShell

Description

This PowerShell script implements a Pomodoro timer, a time management method that alternates work periods with short breaks. It displays a progress bar in the console and can optionally show a notification using the BurntToast module when a work or break session is complete.

Features

  • Pomodoro Timer: Starts a Pomodoro timer with configurable work and break durations.
  • Progress Bar: Displays a progress bar in the console, showing the elapsed time.
  • Customizable Colors: The progress bar's start and end colors can be customized.
  • Notifications: Sends a Windows notification when a work or break session is finished (requires the BurntToast module).
  • Aliases: Provides convenient aliases (work and rest) for starting work and break sessions.
  • Error Handling: Checks for BurntToast and attempts to install it if missing.

Prerequisites

  • PowerShell: This script requires PowerShell 5.1 or later, which is typically included with Windows.
  • BurntToast Module (Optional): For desktop notifications, the BurntToast module is required. The script attempts to install it automatically if it's not already present. If the installation fails, the script will still function, but without notifications.
  • logo.jpg (Optional): For a custom logo in the notification, place a "logo.jpg" in the same directory as the script.

How to Use

  1. Save the Script: Save the PowerShell script to a file (e.g., Pomodoro.ps1).

  2. Open PowerShell: Open a PowerShell console.

  3. Navigate to the Script's Directory: Use the cd command to navigate to the directory where you saved the script. For example:

    cd C:\Users\YourUsername\Documents
  4. Import the Module: Import the script as a module:

    Import-Module .\Pomodoro.ps1
  5. Run the Timer: Use the Start-Pomodoro function or the work and rest aliases to start the timer.

    • To start a work session with the default settings (45 minutes, Aqua to MintCream):

      work
    • To start a rest session with the default settings (10 minutes, LightGreen):

      rest
    • To start a work session with custom settings:

      Start-Pomodoro -Mode work -Minutes 60 -startColor Yellow -endColor Orange

Functions and Parameters

Start-Pomodoro Function

Starts the Pomodoro timer.

Parameters:

  • Mode (String, Optional): The mode of the session. Valid values are "work" or "rest". Default is "work".
  • Minutes (Int, Optional): The duration of the session in minutes. Default is 45 for work and 10 for rest.
  • startColor (System.Drawing.Color, Optional): The starting color of the progress bar. Default is Aqua.
  • endColor (System.Drawing.Color, Optional): The ending color of the progress bar. Default is MintCream.

work Alias

Starts a work session with default settings (45 minutes, Aqua to MintCream). Equivalent to:

Start-Pomodoro -Mode "work" -Minutes 45 -startColor Aqua -endColor MintCream
rest AliasStarts a rest session with default settings (10 minutes, LightGreen). Equivalent to:Start-Pomodoro -Mode "rest" -Minutes 10 -startColor LightGreen
CustomizationSession Durations: You can change the default work and rest durations by modifying the -Minutes parameter in the Start-Pomodoro function or when using the work and rest aliases.Progress Bar Colors: You can customize the progress bar colors using the -startColor and -endColor parameters.  PowerShell can accept color names (e.g., Red, Green, Blue) or you can use the [System.Drawing.Color] class to specify RGB values.  For example:[System.Drawing.Color]::Red[System.Drawing.Color]::FromArgb(255, 0, 0) (Red)Notifications: The script uses the BurntToast module for notifications.  You can customize the notification text and appearance by modifying the New-BurntToastNotification calls within the Start-Pomodoro function.  See the BurntToast documentation for more information: https://github.com/Windos/BurntToastNotification Logo: To add a custom logo to the notification, place a file named "logo.jpg" in the same directory as the script. The script will automatically use this logo if it exists.Example Usage# Start a 60-minute work session with a yellow to orange progress bar.
Start-Pomodoro -Mode work -Minutes 60 -startColor Yellow -endColor Orange

Start a 15-minute rest session with a blue to white progress bar

Start-Pomodoro -Mode rest -Minutes 15 -startColor Blue -endColor White

Use the aliases

work # Start a default work session
rest # Start a default rest session

OutputThe script displays a progress bar in the PowerShell console, along with the remaining time and the current mode (work or rest). When a session is complete, a Windows notification is shown (if BurntToast is installed).NotesThe script uses Start-Sleep to pause execution, which may affect other PowerShell operations.The progress bar updates every second.The script attempts to install the BurntToast module if it's not found, but this may require administrator privileges and an internet connection.The [char]0x2588 character is a solid block, and [char]0x2591 is a light shade character.

I am currently using the following image as logo:
logo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment