diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-07-14 01:50:54 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-07-14 01:50:54 +0530 |
commit | 193034436557fb26adbc26f5fbd847016f6fe0be (patch) | |
tree | 4595efd18ce4e2e0f1ed4a23f59c8015304a965a | |
parent | 12a93c325cf5a7ffa624631450bdb5ace1715753 (diff) |
CLI Pomodoro script with custom sound quotes :]
-rwxr-xr-x | .scripts/pomodoro | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/.scripts/pomodoro b/.scripts/pomodoro new file mode 100755 index 0000000..8e60106 --- /dev/null +++ b/.scripts/pomodoro @@ -0,0 +1,56 @@ +#!/bin/bash + +# Dependency check +[ $(command -v timer) ] || { echo "Please install timer"; exit 1; } +[ $(command -v lolcat) ] || { echo "Please install lolcat"; exit 1; } + +# Folder with subdirectories pre-work,post-work,post-break +# with custom sound files in the format Person-Quote.wav +soundfolder="$HOME/.local/share/voices" + +declare -A pomo_options +pomo_options["work"]="25" +pomo_options["break"]="5" + +# Check if a valid option is provided +if [ -z "$1" ] || [ -z "${pomo_options[$1]}" ]; then + echo "Please provide a valid option: work or break." + exit 1 +fi + +val="$1" +reps=${2:-1} # if 2nd argument(repetitions) is not provided by default take 1 + +# Determine the starting session type +if [ "$1" == "work" ]; then + sessions=("work" "break") +else + sessions=("break" "work") +fi + +# Run the timer and end with a custom sound + notification +for (( i=1; i<=reps; i++ )); do + for session in "${sessions[@]}"; do + if [ "$session" == "work" ]; then + # If first work-rep play pre-work sound + if [ $i -eq 1 ]; then + pre_work_sound=$(find "$soundfolder/pre-work" -type f | shuf -n 1) # Person-Quote.wav + title="${pre_work_sound##*/}" # Extract filename without directory + quote="${pre_work_sound##*-}" # Extract the part after hypher + notify-send "${title%%-*}" "${quote%.wav}" # Extract before hyphen, Remove .wav extension + paplay "$pre_work_sound" + fi + # Assign post-work sound + sound_file=$(find "$soundfolder/post-work" -type f | shuf -n 1) # Person-Quote.wav + else + # Else assign post-break sound + sound_file=$(find "$soundfolder/post-break" -type f | shuf -n 1) # Person-Quote.wav + fi + echo "Pomodoro $i: $session" | lolcat + timer "${pomo_options[$session]}"s no_audio + # Play a sound when each timer ends + sound_file_name="${sound_file##*/}" # Extract filename without directory + notify-send "${sound_file_name%%-*}" "$(echo "${sound_file_name#*-}" | sed 's/\.wav$//')" # Person: Quote + paplay "$sound_file" + done +done |