diff options
author | Saumit Dinesan <justsaumit@protonmail.com> | 2023-07-20 04:44:34 +0530 |
---|---|---|
committer | Saumit Dinesan <justsaumit@protonmail.com> | 2023-07-20 04:44:34 +0530 |
commit | e2e58890e820fa4c140a4378395595f8acbbeb0a (patch) | |
tree | 31b0f2ae33a11756015aa1e87f61677525e3306b | |
parent | 8fb88ca72eee04065ffb1a45e1fc2be7bccb1c1e (diff) |
BashModoro - Incorporating timer as function + reduce dependency, Error Handling by set/unset + sample voices
16 files changed, 85 insertions, 12 deletions
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 Binary files differnew file mode 100644 index 0000000..2539fca --- /dev/null +++ b/soundfolder/post-break/Gustavo-I expect results. Let's not disappoint.wav 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 Binary files differnew file mode 100644 index 0000000..5227628 --- /dev/null +++ b/soundfolder/post-break/Gustavo-The best work is done after a good rest. Now, let's get back to it.wav 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 Binary files differnew file mode 100644 index 0000000..1e35813 --- /dev/null +++ b/soundfolder/post-break/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav 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 Binary files differnew file mode 100644 index 0000000..87b60ba --- /dev/null +++ b/soundfolder/post-break/Kanye-Let's crush this next pomodoro.wav 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 Binary files differnew file mode 100644 index 0000000..da01c9e --- /dev/null +++ b/soundfolder/post-break/Kanye-Time to get back to work! You can do this.wav 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 Binary files differnew file mode 100644 index 0000000..b1d8058 --- /dev/null +++ b/soundfolder/post-work/Kanye-Come back refreshed and ready to focus.wav 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 Binary files differnew file mode 100644 index 0000000..fa135a8 --- /dev/null +++ b/soundfolder/post-work/Kanye-Take a few minutes to stretch, walk around, or fill up the bottle.wav 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 Binary files differnew file mode 100644 index 0000000..fddef24 --- /dev/null +++ b/soundfolder/post-work/Kanye-Time for some break my man.wav 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 Binary files differnew file mode 100644 index 0000000..90be7c7 --- /dev/null +++ b/soundfolder/pre-work/Gustavo-The only way to get ahead is to keep moving forward. So, let's not waste any time.wav 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 Binary files differnew file mode 100644 index 0000000..bc85d0a --- /dev/null +++ b/soundfolder/pre-work/Gustavo-The world does not reward mediocrity. It rewards excellence. Be Better.wav 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 Binary files differnew file mode 100644 index 0000000..30d631e --- /dev/null +++ b/soundfolder/pre-work/Gustavo-We have a business to run. Let's not forget that, Saumit.wav 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 Binary files differnew file mode 100644 index 0000000..7ed123b --- /dev/null +++ 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 diff --git a/soundfolder/pre-work/Kanye-I'm focused and determined.wav b/soundfolder/pre-work/Kanye-I'm focused and determined.wav Binary files differnew file mode 100644 index 0000000..16ec23e --- /dev/null +++ b/soundfolder/pre-work/Kanye-I'm focused and determined.wav 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 Binary files differnew file mode 100644 index 0000000..661c8c8 --- /dev/null +++ b/soundfolder/pre-work/Kanye-I'm going to make my mark on the world.wav |