From ae011963da3fb93ee94d8f8e32ec0c5387b05b1c Mon Sep 17 00:00:00 2001 From: th33xitus Date: Wed, 20 Jul 2022 22:41:42 +0200 Subject: [PATCH] fix: install mainsail theme to correct folder (fixes #222) Signed-off-by: Dominik Willner --- scripts/mainsail.sh | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/scripts/mainsail.sh b/scripts/mainsail.sh index 7c27715..c268425 100644 --- a/scripts/mainsail.sh +++ b/scripts/mainsail.sh @@ -377,16 +377,34 @@ function ms_theme_installer_menu() { } function ms_theme_install() { - local theme_url=${1} theme_name theme_note - theme_name=${2} theme_note=${3} + read_kiauh_ini "${FUNCNAME[0]}" - local config_folders target_folders=() - config_folders=$(find "${KLIPPER_CONFIG}" -mindepth 1 -maxdepth 1 -type d | sort) + local theme_url + local theme_name + local theme_note + theme_url=${1} + theme_name=${2} + theme_note=${3} - ### build target folder array - for folder in ${config_folders}; do - target_folders+=("${folder}") - done + local folder_arr + local folder_names="${multi_instance_names}" + local target_folders=() + + IFS=',' read -r -a folder_arr <<< "${folder_names}" + + ### build theme target folder array + if (( ${#folder_arr[@]} > 1 )); then + for folder in "${folder_arr[@]}"; do + ### instance names/identifier of only numbers need to be prefixed with 'printer_' + if [[ ${folder} =~ ^[0-9]+$ ]]; then + target_folders+=("${KLIPPER_CONFIG}/printer_${folder}") + else + target_folders+=("${KLIPPER_CONFIG}/${folder}") + fi + done + else + target_folders+=("${KLIPPER_CONFIG}") + fi if (( ${#target_folders[@]} > 1 )); then top_border @@ -430,7 +448,10 @@ function ms_theme_delete() { target_folders+=("${folder}") done - if (( ${#target_folders[@]} > 0 )); then + if (( ${#target_folders[@]} == 0 )); then + status_msg "No Themes installed!\n" + return + elif (( ${#target_folders[@]} > 1 )); then top_border echo -e "| Please select the printer you want to remove the |" echo -e "| theme installation from. |" @@ -447,9 +468,6 @@ function ms_theme_delete() { [[ ${target} =~ ${re} && ${target} -lt ${#target_folders[@]} ]] && break error_msg "Invalid command!" done - else - status_msg "No Themes installed!\n" - return fi status_msg "Removing ${target_folders[${target}]} ..."