Trim the space at the end of MESSAGE, and create a test habbit.

This commit is contained in:
Out Of Ideas 2023-12-01 19:54:11 -06:00
parent faa1f7df0b
commit c5008018e9

View file

@ -26,6 +26,10 @@
# 01/12/2023 Out Of Ideas Got script working for one #
# habbit. #
# #
# 01/12/2023 Out Of Ideas Trim the space at the end of #
# MESSAGE, and create a test #
# habbit. #
# #
############################################################
############################################################
############################################################
@ -177,6 +181,7 @@ SECOND="1000"
# Habits
# HABIT TIME DURATION Message
# PRACTICE=("09:00" "$HOUR" "Practice")
#TEST=("$(date -d '+1 minute' '+%H:%M')" "$MINUTE" "This is a test")
PRACTICE_GUITAR=("17:00" "$((2 * $HOUR))" "Practice Guitar")
PRACTICE_KARATE=("19:00" "$((2 * $HOUR))" "Practice Karate")
STRETCH=("19:00" "$((2 * $HOUR))" "Stretch")
@ -186,6 +191,16 @@ HABITS=("${PRACTICE_GUITAR[@]}" "${PRACTICE_KARATE[@]}" "${STRETCH[@]}" "${SING[
# Unset variables
unset VERBOSE
############################################################
# Initialize Functions #
############################################################
trim_string() {
# Usage: trim_string " example string "
: "${1#"${1%%[![:space:]]*}"}"
: "${_%"${_##*[![:space:]]}"}"
printf '%s\n' "$_"
}
############################################################
# Process the input options. Add options as needed. #
############################################################
@ -227,7 +242,7 @@ do
fi
DURATION=$(echo "$HABIT" | awk '{ print $2 }')
MESSAGE=$(echo "$HABIT" | awk '{ str=""; for (i = 3; i <= NF; i++) str = str $i " "; print str }')
MESSAGE=$(trim_string "$(echo "$HABIT" | awk '{ str=""; for (i = 3; i <= NF; i++) str = str $i " "; print str }')")
TIME=$(echo "$HABIT" | awk '{ print $1 }')