Skip to content

Instantly share code, notes, and snippets.

@mopa
Last active September 10, 2023 08:13
Show Gist options
  • Save mopa/9de05a1a854aaa4ce6a6b2cc3e6983ad to your computer and use it in GitHub Desktop.
Save mopa/9de05a1a854aaa4ce6a6b2cc3e6983ad to your computer and use it in GitHub Desktop.
CLI Pomodoro
#!/usr/bin/env bash
#
# Based on this https://gist.github.com/bashbunni/3880e4194e3f800c4c494de286ebc1d7
# Requirements: notify-send (should ship with your distro), lolcat, timer (https://github.com/caarlos0/timer)
# Example of usage: ./pomodoro.sh work
#
set -euo pipefail
declare -A pomo_options
default_work_time=${POMO_WORK_TIME:-45}
default_break_time=${POMO_BREAK_TIME:-10}
pomo_options["work"]="$default_work_time"
pomo_options["break"]="$default_break_time"
usage() {
echo "Usage: $0 [work|break]"
exit 1
}
command_exists() {
command -v "$1" >/dev/null 2>&1
}
if ! command_exists lolcat ||
! command_exists notify-send ||
! command_exists timer; then
echo "Error: Required utilities (lolcat, notify-send, timer) not found."
exit 1
fi
pomodoro() {
local val="$1"
if [ -n "${pomo_options[$val]}" ]; then
echo "$val" | lolcat
timer "${pomo_options[$val]}m"
notify-send --app-name=Pomodoro🍅 \
"$(tr '[:lower:]' '[:upper:]' <<<"${val:0:1}")${val:1} session done 🍅"
else
echo "Invalid option: $val"
usage
fi
}
main() {
if [ "$#" -ne 1 ]; then
usage
fi
pomodoro "$1"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment