From e2e58890e820fa4c140a4378395595f8acbbeb0a Mon Sep 17 00:00:00 2001 From: Saumit Dinesan Date: Thu, 20 Jul 2023 04:44:34 +0530 Subject: BashModoro - Incorporating timer as function + reduce dependency, Error Handling by set/unset + sample voices --- bashmodoro.sh | 94 ++++++++++++++++++--- soundfolder/README.md | 3 + ...tavo-I expect results. Let's not disappoint.wav | Bin 0 -> 236330 bytes ...fter a good rest. Now, let's get back to it.wav | Bin 0 -> 402770 bytes ...oving forward. So, let's not waste any time.wav | Bin 0 -> 384194 bytes .../Kanye-Let's crush this next pomodoro.wav | Bin 0 -> 174658 bytes ...e-Time to get back to work! You can do this.wav | Bin 0 -> 218496 bytes ...anye-Come back refreshed and ready to focus.wav | Bin 0 -> 185060 bytes ...stretch, walk around, or fill up the bottle.wav | Bin 0 -> 277196 bytes .../post-work/Kanye-Time for some break my man.wav | Bin 0 -> 132304 bytes ...oving forward. So, let's not waste any time.wav | Bin 0 -> 384194 bytes ...ediocrity. It rewards excellence. Be Better.wav | Bin 0 -> 331438 bytes ...iness to run. Let's not forget that, Saumit.wav | Bin 0 -> 271252 bytes ...ou are are willing to put in the effort. GO.wav | Bin 0 -> 347042 bytes .../pre-work/Kanye-I'm focused and determined.wav | Bin 0 -> 138248 bytes ...anye-I'm going to make my mark on the world.wav | Bin 0 -> 187288 bytes 16 files changed, 85 insertions(+), 12 deletions(-) create mode 100644 soundfolder/README.md create mode 100644 soundfolder/post-break/Gustavo-I expect results. Let's not disappoint.wav create mode 100644 soundfolder/post-break/Gustavo-The best work is done after a good rest. Now, let's get back to it.wav create mode 100644 soundfolder/post-break/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav create mode 100644 soundfolder/post-break/Kanye-Let's crush this next pomodoro.wav create mode 100644 soundfolder/post-break/Kanye-Time to get back to work! You can do this.wav create mode 100644 soundfolder/post-work/Kanye-Come back refreshed and ready to focus.wav create mode 100644 soundfolder/post-work/Kanye-Take a few minutes to stretch, walk around, or fill up the bottle.wav create mode 100644 soundfolder/post-work/Kanye-Time for some break my man.wav create mode 100644 soundfolder/pre-work/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav create mode 100644 soundfolder/pre-work/Gustavo-The world does not reward mediocrity. It rewards excellence. Be Better.wav create mode 100644 soundfolder/pre-work/Gustavo-We have a business to run. Let's not forget that, Saumit.wav create mode 100644 soundfolder/pre-work/Gustavo-You have the potential to achieve great things, if you are are willing to put in the effort. GO.wav create mode 100644 soundfolder/pre-work/Kanye-I'm focused and determined.wav create mode 100644 soundfolder/pre-work/Kanye-I'm going to make my mark on the world.wav diff --git a/bashmodoro.sh b/bashmodoro.sh index 290208b..f984b44 100755 --- a/bashmodoro.sh +++ b/bashmodoro.sh @@ -1,17 +1,79 @@ #!/bin/bash # Dependency check -[ $(command -v timer) ] || { echo "Please install timer"; exit 1; } -[ $(command -v lolcat) ] || { echo "Please install lolcat"; exit 1; } +[ $(command -v libnotify) ] || { echo "Please install libnotify for notifications"; 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" +# Change to s,m or h for- seconds,minutes and hours +default_time_unit=m declare -A pomo_options pomo_options["work"]="25" pomo_options["break"]="5" +function timer() { + local bwhite='\033[1m' + local borange='\e[1;38;5;202m' + local bred='\e[1;38;5;196m' + local nc='\033[0m' + local first_arg_error_msg="Invalid input! Please provide a valid time in seconds, minutes (m), hours (h), or a combination (e.g., 2h30m)." + # Function to convert time to seconds + function convert_to_seconds() { + local input=$1 + local time_mode=${input: -1} + local value=${input::-1} + if [[ $time_mode =~ ^[hms]$ ]]; then + case $time_mode in + "s") echo "$value";; + "m") echo "$((value * 60))";; + "h") echo "$((value * 3600))";; + esac + else + time_mode="s" # Assign default time_mode 's' + echo "$input" # Treat single number as seconds + fi + } + # Check if arguments are provided + if [[ $# -eq 0 || ! $1 =~ ^[0-9]+([hms])?$ ]]; then + echo -e "$first_arg_error_msg" + exit 1 + fi + # Extract total_time and time_mode from the input arguments + local total_time=$(convert_to_seconds "$1") + # Assign time_mode + if [[ $1 =~ [hms]$ ]]; then + local time_mode=${1: -1} + local value=${1::-1} + else + local value=$1 + local time_mode="s" + fi + # display timer settings + echo -e "\n\n\tSession duration: ${bwhite}$value$time_mode${nc}\n\t" + # starting timer message + echo -e "\t${bwhite}Starting timer at $(date +"%r")" + echo -e "\t\tTiming in ${bwhite}$value$time_mode${nc}...\n" + # Timer function + function countdown_timer() { + local duration=$1 + local show_timer=false + while [[ $duration -gt 0 ]]; do + if [[ $duration -le 60 ]]; then + show_timer=true + fi + sleep 1 + duration=$((duration - 1)) + if $show_timer ;then + echo -ne "\r\t\t${bwhite}Timer: $duration sec${nc}" + fi + done + echo -e "\n\t\t${bwhite}Timer ended at $(date +"%r")${nc}\n" + } + countdown_timer $total_time +} + # Check if a valid option is provided if [ -z "$1" ] || [ -z "${pomo_options[$1]}" ]; then echo "Please provide a valid option: work or break." @@ -35,10 +97,13 @@ for (( i=1; i<=reps; i++ )); do # 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" + # check is pre_work_sound is set, if yes then executes else skip + if [[ -n "$pre_work_sound" ]]; then + 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 fi # Assign post-work sound sound_file=$(find "$soundfolder/post-work" -type f | shuf -n 1) # Person-Quote.wav @@ -46,13 +111,18 @@ for (( i=1; i<=reps; i++ )); do # Else assign post-break sound if [ $i -ne $reps ]; then sound_file=$(find "$soundfolder/post-break" -type f | shuf -n 1) # Person-Quote.wav + else unset sound_file fi fi - echo "Pomodoro $i: $session" | lolcat - timer "${pomo_options[$session]}"m 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" + # If lolcat is installed use it, if not run plain + command -v lolcat >/dev/null 2>&1 && { echo "Pomodoro $i: $session" | lolcat; } || echo "Pomodoro $i: $session" + timer "${pomo_options[$session]}""$default_time_unit" + # check is sound_file is set, if yes then executes else skip + if [[ -n "$sound_file" ]]; then + # 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" + fi done done diff --git a/soundfolder/README.md b/soundfolder/README.md new file mode 100644 index 0000000..722c47f --- /dev/null +++ b/soundfolder/README.md @@ -0,0 +1,3 @@ +# Sample Voices +Sample quotes provided by ChatGPT based on famous personalities, tailored specifically for Pomodoro sessions - pre-work(Initially starting), post-work and post-break intervals. +The AI-generated text-to-speech (TTS) features were produced using models trained by justinjohn0306 and Vox Populi. diff --git a/soundfolder/post-break/Gustavo-I expect results. Let's not disappoint.wav b/soundfolder/post-break/Gustavo-I expect results. Let's not disappoint.wav new file mode 100644 index 0000000..2539fca Binary files /dev/null and b/soundfolder/post-break/Gustavo-I expect results. Let's not disappoint.wav differ diff --git a/soundfolder/post-break/Gustavo-The best work is done after a good rest. Now, let's get back to it.wav b/soundfolder/post-break/Gustavo-The best work is done after a good rest. Now, let's get back to it.wav new file mode 100644 index 0000000..5227628 Binary files /dev/null and b/soundfolder/post-break/Gustavo-The best work is done after a good rest. Now, let's get back to it.wav differ diff --git a/soundfolder/post-break/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav b/soundfolder/post-break/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav new file mode 100644 index 0000000..1e35813 Binary files /dev/null and b/soundfolder/post-break/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav differ diff --git a/soundfolder/post-break/Kanye-Let's crush this next pomodoro.wav b/soundfolder/post-break/Kanye-Let's crush this next pomodoro.wav new file mode 100644 index 0000000..87b60ba Binary files /dev/null and b/soundfolder/post-break/Kanye-Let's crush this next pomodoro.wav differ diff --git a/soundfolder/post-break/Kanye-Time to get back to work! You can do this.wav b/soundfolder/post-break/Kanye-Time to get back to work! You can do this.wav new file mode 100644 index 0000000..da01c9e Binary files /dev/null and b/soundfolder/post-break/Kanye-Time to get back to work! You can do this.wav differ diff --git a/soundfolder/post-work/Kanye-Come back refreshed and ready to focus.wav b/soundfolder/post-work/Kanye-Come back refreshed and ready to focus.wav new file mode 100644 index 0000000..b1d8058 Binary files /dev/null and b/soundfolder/post-work/Kanye-Come back refreshed and ready to focus.wav differ diff --git a/soundfolder/post-work/Kanye-Take a few minutes to stretch, walk around, or fill up the bottle.wav b/soundfolder/post-work/Kanye-Take a few minutes to stretch, walk around, or fill up the bottle.wav new file mode 100644 index 0000000..fa135a8 Binary files /dev/null and b/soundfolder/post-work/Kanye-Take a few minutes to stretch, walk around, or fill up the bottle.wav differ diff --git a/soundfolder/post-work/Kanye-Time for some break my man.wav b/soundfolder/post-work/Kanye-Time for some break my man.wav new file mode 100644 index 0000000..fddef24 Binary files /dev/null and b/soundfolder/post-work/Kanye-Time for some break my man.wav differ diff --git a/soundfolder/pre-work/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav b/soundfolder/pre-work/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav new file mode 100644 index 0000000..90be7c7 Binary files /dev/null and b/soundfolder/pre-work/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav differ diff --git a/soundfolder/pre-work/Gustavo-The world does not reward mediocrity. It rewards excellence. Be Better.wav b/soundfolder/pre-work/Gustavo-The world does not reward mediocrity. It rewards excellence. Be Better.wav new file mode 100644 index 0000000..bc85d0a Binary files /dev/null and b/soundfolder/pre-work/Gustavo-The world does not reward mediocrity. It rewards excellence. Be Better.wav differ diff --git a/soundfolder/pre-work/Gustavo-We have a business to run. Let's not forget that, Saumit.wav b/soundfolder/pre-work/Gustavo-We have a business to run. Let's not forget that, Saumit.wav new file mode 100644 index 0000000..30d631e Binary files /dev/null and b/soundfolder/pre-work/Gustavo-We have a business to run. Let's not forget that, Saumit.wav differ diff --git a/soundfolder/pre-work/Gustavo-You have the potential to achieve great things, if you are are willing to put in the effort. GO.wav b/soundfolder/pre-work/Gustavo-You have the potential to achieve great things, if you are are willing to put in the effort. GO.wav new file mode 100644 index 0000000..7ed123b Binary files /dev/null and b/soundfolder/pre-work/Gustavo-You have the potential to achieve great things, if you are are willing to put in the effort. GO.wav differ diff --git a/soundfolder/pre-work/Kanye-I'm focused and determined.wav b/soundfolder/pre-work/Kanye-I'm focused and determined.wav new file mode 100644 index 0000000..16ec23e Binary files /dev/null and b/soundfolder/pre-work/Kanye-I'm focused and determined.wav differ diff --git a/soundfolder/pre-work/Kanye-I'm going to make my mark on the world.wav b/soundfolder/pre-work/Kanye-I'm going to make my mark on the world.wav new file mode 100644 index 0000000..661c8c8 Binary files /dev/null and b/soundfolder/pre-work/Kanye-I'm going to make my mark on the world.wav differ -- cgit v1.2.3