Skip to content

Instantly share code, notes, and snippets.

@bashbunni
Created January 4, 2023 16:28
Show Gist options
  • Save bashbunni/3880e4194e3f800c4c494de286ebc1d7 to your computer and use it in GitHub Desktop.
Save bashbunni/3880e4194e3f800c4c494de286ebc1d7 to your computer and use it in GitHub Desktop.
CLI Pomodoro for Linux
# 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'"
@alonss0
Copy link

alonss0 commented Jan 16, 2023

I was looking for this. Thank u so much 🥇

@ItIsCiprian
Copy link

Thank you - it simple and efficient

@eduardo-sdev
Copy link

Thanks ❤️

@gemcave
Copy link

gemcave commented Jan 17, 2023

thankthank Joyge

@moonR2
Copy link

moonR2 commented Jan 17, 2023

Thanks Bash <3

@samuelpx
Copy link

samuelpx commented Jan 17, 2023

Great work! I'm looking into ways to have this loop from work to break continuously so I don't have to manually reset this everytime, any idea on what would be the best way to do that?

@Ajexsen
Copy link

Ajexsen commented Jan 17, 2023

Great work! I'm looking into ways to have this loop from work to break continuously so I don't have to manually reset this everytime, any idea on what would be the best way to do that?

Something like this should work (untested):

cycle_work_break(){
    for i in $(seq $1); do
        pomodoro 'work'
        pomodoro 'break'
    done
}

then you can provide the number you want it to repeat like so: cycle_work_break 8
And if you want to repeat it indefinitely, you can just change it to while loop (while true)

@samuelpx
Copy link

samuelpx commented Jan 17, 2023

Yeah, that worked, thank you! I tried something very similar but figured I was doing something wrong since it wasn't working, turns out the error was with "spd-say "'$val' session done"" because of my WSL installation (if that comes up for anyone).

@mariohoff
Copy link

Works great. Thanks!
Just a quick addition: Requires lolcat too, obviously.

@jprostko
Copy link

jprostko commented Jan 21, 2023

I modified this slightly, getting rid of the pipe into lolcat (I generally don't install lolcat or variants like lolcat-rs on my systems) and also using notify-send to send me a normal system notification instead of using spd-say to provide an audio notification. I also added a quick if statement to have a different system notification depending on whether the work session or break session had just ended. It works well enough for me.

@kbakdev
Copy link

kbakdev commented Jan 22, 2023

Thanks

@brianbert
Copy link

brianbert commented Jan 23, 2023

Great work! I'm looking into ways to have this loop from work to break continuously so I don't have to manually reset this everytime, any idea on what would be the best way to do that?

I'm not sure if this is helpful for you, but you can adjust the work / break times as well as the number of loops using terminal commands.
Keep in mind that these changes are only for the current session, once you close the terminal you have to do it again. If you want to make them permanent, you'll need to adjust them within the script.

Commands (Change the Ñ for the number you want):

Start pomodoro and set loops: doro Ñ (If you type doro without specifying a number, it will perform the default number of loops that are set in the script.).

Change work time: cp work Ñ

Change break time: cp break Ñ

declare -A pomo_options
pomo_options["work"]="45"
pomo_options["break"]="10"

pomodoro() {
  val=$1
  echo $val | lolcat
  timer ${pomo_options["$val"]}m
  spd-say "'$val' session done"
  notify-send --app-name=Pomodoro🍅 "'$val' session done 🍅"
}

start_pomodoro() {
  # Number of times to repeat the loop, default is 2
  if [ -n "$1" ] && [ "$1" -eq "$1" ] 2>/dev/null; then
    num_loops=$1
  else
   # Default loops
    num_loops=2
  fi

  for i in $(seq 1 $num_loops); do
    pomodoro "work"
    pomodoro "break"
  done
}
change_pomo() {
  if [ -n "$1" ] && [ -n "$2" ]; then
    pomo_options["$1"]="$2"
    echo "The $1 time has been changed to $2 minutes"
  else
    echo "Please provide valid parameters: change_pomo [work/break] [time_in_minutes]"
  fi
}

alias doro=start_pomodoro
alias wo="pomodoro 'work'"
alias br="pomodoro 'break'"
alias cp=change_pomo

Also added the system notifications with notify-send

@LuizHGodoy
Copy link

I modified this slightly, getting rid of the pipe into lolcat (I generally don't install lolcat or variants like lolcat-rs on my systems) and also using notify-send to send me a normal system notification instead of using spd-say to provide an audio notification. I also added a quick if statement to have a different system notification depending on whether the work session or break session had just ended. It works well enough for me.

can you show us how u did it?

@johannesnauta
Copy link

For those that use bash-shell instead of the zsh-shell, here is a quick'n'dirty modification to the script.

(Added an Emacs timer to it to avoid unlimited fiddling with my Emacs-config for obvious reasons.)

#/bin/bash
declare -A pomo_options
pomo_options=(
    ["work"]="45"
    ["break"]="10"
    ["emacs"]="30"
)

pomodoro () {
  if [ -n "$1" -a -n "{pomo_options["$1"]}" ]; then
  val=$1;
  timer "${pomo_options["$val"]}m"
  notify-send "'$val' session done"
  fi
}

alias wo="pomodoro 'work'"
alias br="pomodoro 'break'"
alias em="pomodoro 'emacs'"

@edgarsilva
Copy link

This one for Fish 🐟 users

function pomodoro 
  echo $argv[1] | lolcat
  timer "$argv[2]"m 
  spd-say "'$argv[1]' session done"
end

alias po="pomodoro"
alias wo="pomodoro work 45"
alias br="pomodoro break 10"

@bbazsi41
Copy link

Hey! Can someone please explain how exactly to run it?

@brianbert
Copy link

Hey! Can someone please explain how exactly to run it?

If you have zsh you have to find your .zshrc file in your home directory, open it with a text editor and paste the code at the bottom.

@bbazsi41
Copy link

Thank you. Yes, this is what I did, I copied the code at the bottom of it, saved it and closed it.
But if I wanted to run 'work' or 'break' I got the error message: command not found.

@brianbert
Copy link

Thank you. Yes, this is what I did, I copied the code at the bottom of it, saved it and closed it. But if I wanted to run 'work' or 'break' I got the error message: command not found.

did you try running it with wo and br ?

@bbazsi41
Copy link

bbazsi41 commented Jan 28, 2023

Yes, but unfortunately I got the same errors:
zsh: command not found: wo
zsh: command not found: br

@brianbert
Copy link

Yes, but unfortunately I got the same errors: zsh: command not found: wo zsh: command not found: br

Things you can try:

  1. Close your terminal and open it again, as the changes may not take effect until the terminal is restarted.
  2. Ensure that you have installed all necessary dependencies, such as timer, lolcat, and spd-say.
  3. Verify that the code you pasted is complete.
  4. Restart your system to see if that resolves the issue.
  5. Reinstall zsh and paste the code again.
  6. Realize that you were using Windows all along.
  7. Fall into despair and cry in the shower.
  8. Someone in the future will help you by posting the solution here. (happy ending)

@bbazsi41
Copy link

Except the last 3 points I did everyhing and now it is working with 'wo' and 'br'.
Thank you for your help!

@AIMadeScripts
Copy link

AIMadeScripts commented Jan 29, 2023

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```

@cornuel
Copy link

cornuel commented Jan 31, 2023

So simple yet very useful, thank you! 💪🏻

@hglbrg
Copy link

hglbrg commented Feb 14, 2023

I added some artificial intelligense neural network framework library laser surgery hack scripting hackerman logic to 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
  clear
  echo $val | lolcat
  timer ${pomo_options["$val"]}m
  spd-say "'$val' session done"
  fi
}

alias wo="pomodoro 'work'"
alias br="pomodoro 'break'"

which improves it by 405.33 (repeating of course) %

@paolojulian
Copy link

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.

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