From 30aaebb7f81ca696b164755d770ae3dc5de6ea74 Mon Sep 17 00:00:00 2001 From: speedie Date: Tue, 18 Apr 2023 18:24:35 +0200 Subject: [PATCH] various improvements this commit also downgrades code quality slightly (by not using readarray). while readarray is cleaner, it is not compatible with older bash versions (< version 4) so a while loop will have to do. i may change this later. --- scripts/spmenu_run | 54 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/scripts/spmenu_run b/scripts/spmenu_run index 3666f97..44654d7 100755 --- a/scripts/spmenu_run +++ b/scripts/spmenu_run @@ -401,11 +401,25 @@ main_desktop() { else # we have entries, let's populate the arrays command -v desktop_pre_func > /dev/null && desktop_pre_func - readarray -t it_title < "$TEMPORARY_DIR/../.title" - readarray -t it_exec < "$TEMPORARY_DIR/../.exec" - readarray -t it_icon < "$TEMPORARY_DIR/../.icon" - readarray -t it_file < "$TEMPORARY_DIR/../.file" + # read title + while read -r p; do + it_title+=("$p") + done < "$TEMPORARY_DIR/../.title" + # read icon + while read -r p; do + it_icon+=("$p") + done < "$TEMPORARY_DIR/../.icon" + + # read executable + while read -r p; do + it_exec+=("$p") + done < "$TEMPORARY_DIR/../.exec" + + # read file + while read -r p; do + it_file+=("$p") + done < "$TEMPORARY_DIR/../.file" # finally print all of it for i in "${!it_title[@]}"; do @@ -427,21 +441,37 @@ main_desktop() { [ -z "$menusel" ] && return 1 \ || printf "User input: %s\n" "$menusel" >> "$LOGFILE" - w_array() { - readarray -t it_title < "$TEMPORARY_DIR/../.title" - readarray -t it_exec < "$TEMPORARY_DIR/../.exec" - readarray -t it_icon < "$TEMPORARY_DIR/../.icon" - readarray -t it_file < "$TEMPORARY_DIR/../.file" + exec_program() { + # read title + while read -r p; do + it_title+=("$p") + done < "$TEMPORARY_DIR/../.title" + + # read icon + while read -r p; do + it_icon+=("$p") + done < "$TEMPORARY_DIR/../.icon" + + # read executable + while read -r p; do + it_exec+=("$p") + done < "$TEMPORARY_DIR/../.exec" + + # read file + while read -r p; do + it_file+=("$p") + done < "$TEMPORARY_DIR/../.file" + # set exec [ -z "${it_exec[1]}" ] && printf "Executable array is empty.\n" >> "$LOGFILE" for i in "${!it_title[@]}"; do if [ "${it_title[i]}" = "$menusel" ]; then exec="${it_exec[i]}" - printf "Current file: '%s'\n" "${it_file[i]}" >> "$LOGFILE" + printf "Current file: '%s'\nIndex: '%s'\n" "${it_file[i]}" "${i}" >> "$LOGFILE" break; else - printf "Executable %s is: %s" "$i" "${it_exec[i]}" >> "$LOGFILE" + printf "Executable %s is: '%s'\n" "$i" "${it_exec[i]}" >> "$LOGFILE" fi done @@ -453,7 +483,7 @@ main_desktop() { fi } - w_array + exec_program "$@" } prep() { mkdir -p "$TEMPORARY_DIR"; rm -f "$LOGFILE"; touch "$LOGFILE"; }