-
Star
(271)
You must be signed in to star a gist -
Fork
(30)
You must be signed in to fork a gist
-
-
Save bashbunni/3880e4194e3f800c4c494de286ebc1d7 to your computer and use it in GitHub Desktop.
| # study stream aliases | |
| # Requires https://github.com/caarlos0/timer to be installed. spd-say should ship with your distro | |
| declare -A pomo_options | |
| pomo_options["work"]="45" | |
| pomo_options["break"]="10" | |
| pomodoro () { | |
| if [ -n "$1" -a -n "${pomo_options["$1"]}" ]; then | |
| val=$1 | |
| echo $val | lolcat | |
| timer ${pomo_options["$val"]}m | |
| spd-say "'$val' session done" | |
| fi | |
| } | |
| alias wo="pomodoro 'work'" | |
| alias br="pomodoro 'break'" |
Use with:
./timer.sh work 10
./timer.sh break 10
Will be set in minutes.
Quick install instructions for debian:
sudo apt-get install lolcat
echo 'deb [trusted=yes] https://repo.caarlos0.dev/apt/ /' | sudo tee /etc/apt/sources.list.d/caarlos0.list
sudo apt update
sudo apt install timer
#!/bin/bash
clear
declare -A pomo_options
pomo_options["work"]="45"
pomo_options["break"]="10"
pomodoro () {
if [ -n "$1" -a -n "${pomo_options["$1"]}" ]; then
val=$1
if [ -z "$2" ]; then
minutes=${pomo_options["$val"]}
else
minutes=$2
fi
echo $val | lolcat
timer $minutes"m"
spd-say "'$val' session done"
else
echo "Usage: pomodoro <work|break> [minutes]"
fi
}
if [ "$1" == "work" ]; then
pomodoro "work" "$2"
elif [ "$1" == "break" ]; then
pomodoro "break" "$2"
else
echo "Usage: ./timer.sh <work|break> [minutes]"
fi
#Make sure to install https://github.com/caarlos0/timer
#And make sure to have lolcat installed```
So simple yet very useful, thank you! πͺπ»
This is quite good.
Also, a suggestion of mine is that it would be nice if we can add like a "TODO" list along with it.
How can i add this to my timer, i.e. where should i place this file?
I modified the script a bit just to adjust the duration and added a custom .wav that you could replace with whatever you wanted.
Not sure if this was the best way to go about it all so if I have done anything in a long winded way I would love some feedback.
I made an adjusted version, so you do not have to restart the timer manually and after 4 iterations a longer break is set - and you get notifications :)
pomodoro() {
typeset -A pomo_options
pomo_options["work"]=${1:-25}
pomo_options["break"]=${2:-5}
pomo_options["long_break"]=${3:-15}
local current_phase="work"
if [[ "$1" == "break" ]]; then
current_phase="break"
fi
local pomodoro_count=0
trap - INT
while true; do
local duration_key
local notification_title
local notification_text
local notification_speaker
if [[ "$current_phase" == "work" ]]; then
pomodoro_count=$((pomodoro_count + 1))
duration_key="work"
notification_title="π
Session done"
notification_text="It is now time to take a <b>BREAK</b>!"
notification_speaker="Break time"
else
if (( (pomodoro_count % 4) == 0 && pomodoro_count > 0 )); then
echo "Taking a LONG BREAK!" | lolcat
duration_key="long_break"
else
duration_key="break"
fi
notification_title="π§ Break over"
notification_text="Time to get back to <b>WORK</b>"
notification_speaker="Work time"
fi
echo "$current_phase" | lolcat
timer ${pomo_options["$duration_key"]}m
local timer_exit_status=$?
if [[ "$timer_exit_status" -ne 0 ]]; then
echo "Pomodoro stopped."
break
fi
notify-send -u normal -t 3000 -i alarm "$notification_title" "$notification_text"
spd-say -t male3 -r -10 -p -100 "$notification_speaker"
if [[ "$current_phase" == "work" ]]; then
current_phase="break"
else
current_phase="work"
fi
done
exit
}
alias pomo="pomodoro"
alias wo="pomodoro"
alias br="pomodoro break"To use your .zshrc and the pomodoro function on WSL with Ubuntu 24.04, follow these steps:
β 1. Install Required Tools
Before using your aliases and functions, install the required tools in your WSL environment:
sudo apt update
sudo apt install zsh lolcat espeak # spd-say comes from speech-dispatcher or use espeak as fallbackThen install timer from GitHub (by caarlos0):
# Install Go (required for building the timer)
sudo apt install golang-go
# Clone and install the timer tool
git clone https://github.com/caarlos0/timer.git
cd timer
go build -o timer
sudo mv timer /usr/local/bin/Now timer should be available system-wide.
β
2. Ensure You're Using zsh in WSL
If you're not already using Zsh as your shell in WSL, switch to it:
sudo apt install zsh
chsh -s $(which zsh)Then restart WSL or run zsh.
β
3. Configure .zshrc
Put your function and aliases in the .zshrc file:
nano ~/.zshrcPaste this:
# study stream aliases
# Requires https://github.com/caarlos0/timer to be installed. spd-say should ship with your distro
declare -A pomo_options
pomo_options["work"]="45"
pomo_options["break"]="10"
pomodoro () {
if [ -n "$1" -a -n "${pomo_options["$1"]}" ]; then
val=$1
echo $val | lolcat
timer ${pomo_options["$val"]}m
spd-say "'$val' session done"
fi
}
alias wo="pomodoro 'work'"
alias br="pomodoro 'break'"Then reload it:
source ~/.zshrcβ 4. Run the Commands
Now you can simply run:
wo # starts a 45-minute "work" timer
br # starts a 10-minute "break" timerβ οΈ Note on spd-say in WSL
spd-say may not produce audio output in WSL directly unless you have audio forwarding set up (via PulseAudio or similar). If it doesn't work, consider replacing spd-say with something like espeak or even just a notify-send (if running a Linux GUI).
Example:
espeak "'$val' session done"or remove it if sound isnβt essential.
β How to Send Windows Notifications from WSL
The only way to get native Windows notifications from WSL is to explicitly call Windows tools from WSL, like PowerShell.
βοΈ Step-by-Step: Add Windows Toast Notification
π§ 1. Install the BurntToast module (Windows side)
In a Windows PowerShell terminal (not WSL), run:
Install-Module -Name BurntToast -Force -SkipPublisherCheckYou only need to do this once. BurntToast is a PowerShell module for sending toast notifications.
βοΈ 2. Modify Your pomodoro Function
Update your function to use PowerShell from WSL to send a toast:
pomodoro () {
if [ -n "$1" ] && [ -n "${pomo_options["$1"]}" ]; then
val=$1
echo $val | lolcat
timer ${pomo_options["$val"]}m
espeak "'$val' session done"
powershell.exe -Command "New-BurntToastNotification -Text 'Pomodoro Timer', '$val session done'" > /dev/null 2>&1
fi
}This line:
powershell.exe -Command "New-BurntToastNotification -Text 'Pomodoro Timer', '$val session done'"runs PowerShell on Windows from WSL, and sends the notification natively.
π§ͺ 3. Test It
After timer finishes, you should:
- β
Hear audio (
espeak) - β See a Windows toast notification pop up
for anyone trying to use this on windows you can add this function to your powershell profile
# --- The Main Function ---
function Start-PomoTimer {
param (
[string]$TimerType
)
$pomoOptions = @{
"work" = "50m"
"break" = "10m"
"short" = "5m"
}
# --- REMEMBER TO UPDATE THE PATH OF THE CLONED REPOSITORY HERE ---
$timerPath = "D:\timer\timer.exe"
if ($pomoOptions.ContainsKey($TimerType)) {
$duration = $pomoOptions[$TimerType]
Write-Host "Starting '$TimerType' timer for $duration..."
& $timerPath $duration -n $TimerType
Write-Host "'$TimerType' session done!"
} else {
Write-Host "Invalid timer type: '$TimerType'. Available types: $($pomoOptions.Keys -join ', ')"
}
}
function Start-PomoWork {
Start-PomoTimer -TimerType "work"
}
function Start-PomoBreak {
Start-PomoTimer -TimerType "break"
}
# --- Updated Aliases pointing to the new functions ---
Set-Alias -Name wo -Value Start-PomoWork
Set-Alias -Name br -Value Start-PomoBreak
Check out my setup in this repo β fish-flowmodoro, a simple Fish Shell productivity timer with chill audio cues.
Thanks Bash, love you.
Except the last 3 points I did everyhing and now it is working with 'wo' and 'br'.
Thank you for your help!