diff --git a/scripts/switch_klipper_repo.sh b/scripts/switch_klipper_repo.sh index 765af4f..8739250 100644 --- a/scripts/switch_klipper_repo.sh +++ b/scripts/switch_klipper_repo.sh @@ -43,53 +43,57 @@ function change_klipper_repo_menu() { back_help_footer local option + local num="^[0-9]+$" + local back="^(B|b)$" + local help="^(H|h)$" + while true; do read -p "${cyan}###### Perform action:${white} " option - case "${option}" in - 0 | "$(( option < ${#repos[@]} ))") - select_msg "Repo: ${repos[option]} Branch: ${branches[option]}" - if [[ -d ${KLIPPER_DIR} ]]; then - top_border - echo -e "| ${red}!!! ATTENTION !!!${white} |" - echo -e "| Existing Klipper folder found! Proceeding will remove | " - echo -e "| the existing Klipper folder and replace it with a | " - echo -e "| clean copy of the previously selected source repo! | " - bottom_border - local yn - while true; do - read -p "${cyan}###### Proceed? (Y/n):${white} " yn - case "${yn}" in - Y|y|Yes|yes|"") - select_msg "Yes" - switch_klipper_repo "${repos[${option}]}" "${branches[${option}]}" - set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" - break;; - N|n|No|no) - select_msg "No" - break;; - *) - error_msg "Invalid command!";; - esac - done - else - status_msg "Set custom Klipper repository to:\n ● Repository: ${repos[${option}]}\n ● Branch: ${branches[${option}]}" - set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" - ok_msg "This repo will now be used for new Klipper installations!\n" - fi - break;; - B|b) - clear && print_header - settings_menu - break;; - H|h) - clear && print_header - show_custom_klipper_repo_help - break;; - *) - error_msg "Invalid command!";; - esac + if [[ ${option} =~ ${num} && ${option} -lt ${#repos[@]} ]]; then + select_msg "Repo: ${repos[option]} Branch: ${branches[option]}" + + if [[ -d ${KLIPPER_DIR} ]]; then + top_border + echo -e "| ${red}!!! ATTENTION !!!${white} |" + echo -e "| Existing Klipper folder found! Proceeding will remove | " + echo -e "| the existing Klipper folder and replace it with a | " + echo -e "| clean copy of the previously selected source repo! | " + bottom_border + + local yn + while true; do + read -p "${cyan}###### Proceed? (Y/n):${white} " yn + case "${yn}" in + Y|y|Yes|yes|"") + select_msg "Yes" + switch_klipper_repo "${repos[${option}]}" "${branches[${option}]}" + set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" + break;; + N|n|No|no) + select_msg "No" + break;; + *) + error_msg "Invalid command!";; + esac + done + else + status_msg "Set custom Klipper repository to:\n ● Repository: ${repos[${option}]}\n ● Branch: ${branches[${option}]}" + set_custom_klipper_repo "${repos[${option}]}" "${branches[${option}]}" + ok_msg "This repo will now be used for new Klipper installations!\n" + fi + + elif [[ ${option} =~ ${back} ]]; then + clear && print_header + settings_menu + elif [[ ${option} =~ ${help} ]]; then + clear && print_header + show_custom_klipper_repo_help + else + error_msg "Invalid command!" + fi done + change_klipper_repo_menu }