diff --git a/datepicker.sh b/datepicker.sh index aaf3f19..a93f118 100644 --- a/datepicker.sh +++ b/datepicker.sh @@ -29,6 +29,14 @@ # RETURN: # 0 if success, non-zero otherwise. ####################################### + +# declare month array +declare -A month=( + [Jan]=1 [Feb]=2 [Mar]=3 [Apr]=4 + [May]=5 [Jun]=6 [Jul]=7 [Aug]=8 + [Sep]=9 [Oct]=10 [Nov]=11 [Dec]=12 +) + function datepicker() { if [ -z ${GUI_ICON+x} ]; then GUI_ICON=$XDG_ICO_CALENDAR @@ -62,31 +70,7 @@ function datepicker() { INPUT_DATE=$(kdialog --title="$GUI_TITLE" --icon "$GUI_ICON" --calendar "Select Date") exit_status=$? TEXT_MONTH=$(echo "$INPUT_DATE" | cut -d' ' -f2) - if [ "$TEXT_MONTH" == "Jan" ]; then - MONTH=1 - elif [ "$TEXT_MONTH" == "Feb" ]; then - MONTH=2 - elif [ "$TEXT_MONTH" == "Mar" ]; then - MONTH=3 - elif [ "$TEXT_MONTH" == "Apr" ]; then - MONTH=4 - elif [ "$TEXT_MONTH" == "May" ]; then - MONTH=5 - elif [ "$TEXT_MONTH" == "Jun" ]; then - MONTH=6 - elif [ "$TEXT_MONTH" == "Jul" ]; then - MONTH=7 - elif [ "$TEXT_MONTH" == "Aug" ]; then - MONTH=8 - elif [ "$TEXT_MONTH" == "Sep" ]; then - MONTH=9 - elif [ "$TEXT_MONTH" == "Oct" ]; then - MONTH=10 - elif [ "$TEXT_MONTH" == "Nov" ]; then - MONTH=11 - else #elif [ "$TEXT_MONTH" == "Dec" ]; then - MONTH=12 - fi + MONTH=${month["$TEXT_MONTH"]:-0} DAY=$(echo "$INPUT_DATE" | cut -d' ' -f3) YEAR=$(echo "$INPUT_DATE" | cut -d' ' -f4) diff --git a/helpers.sh b/helpers.sh index 3cbdf28..694000f 100644 --- a/helpers.sh +++ b/helpers.sh @@ -6,6 +6,10 @@ # Variables set in init.sh and used here # shellcheck disable=SC2154 +function listfunc() { + compgen -A function +} + ####################################### # Attempts to run a privileged command (sudo or equivalent) # GLOBALS: @@ -19,6 +23,7 @@ # RETURN: # 0 if success, non-zero otherwise. ####################################### + function superuser() { if [ "$NO_SUDO" == true ]; then (>&2 echo "${red}No sudo available!${normal}") @@ -41,7 +46,7 @@ function superuser() { ####################################### # Set the GUI_TITLE based on the ACTIVITY and APP_NAME # GLOBALS: -# GUI_TITLE +# GUI_TITLE # ACTIVITY # APP_NAME # ARGUMENTS: diff --git a/script-dialog.sh b/script-dialog.sh index ef15cca..5e3bd86 100755 --- a/script-dialog.sh +++ b/script-dialog.sh @@ -3,30 +3,24 @@ # https://github.com/lunarcloud/script-dialog # LGPL-2.1 license -# Get the directory where this script is located +# get the directories SCRIPT_DIALOG_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +CURRENT_FILE="$(realpath -- "${BASH_SOURCE[0]}")" -# Source all modular components -# shellcheck source=./init.sh -source "${SCRIPT_DIALOG_DIR}/init.sh" +# sources everything in folder, excludes current file +for src in ./*.sh +do + [[ "$(realpath -- "$src")" == "$CURRENT_FILE" ]] && continue + source "$src" || exit 1 + #echo "$src" +done -# shellcheck source=./helpers.sh -source "${SCRIPT_DIALOG_DIR}/helpers.sh" +# execute told function +if declare -f "$1" >/dev/null; then + "$1" +else + echo "Function not found" +fi -# shellcheck source=./messages.sh -source "${SCRIPT_DIALOG_DIR}/messages.sh" +# the rest goes there -# shellcheck source=./inputs.sh -source "${SCRIPT_DIALOG_DIR}/inputs.sh" - -# shellcheck source=./lists.sh -source "${SCRIPT_DIALOG_DIR}/lists.sh" - -# shellcheck source=./progressbar.sh -source "${SCRIPT_DIALOG_DIR}/progressbar.sh" - -# shellcheck source=./pickers.sh -source "${SCRIPT_DIALOG_DIR}/pickers.sh" - -# shellcheck source=./datepicker.sh -source "${SCRIPT_DIALOG_DIR}/datepicker.sh"