From bcae0175ec5ca0571e933789409b4f0b5f23f519 Mon Sep 17 00:00:00 2001 From: Santiago Lo Coco Date: Fri, 28 Jan 2022 22:08:32 -0300 Subject: [PATCH] Use generic calcAndRun --- install.sh | 57 ++++++------------------------------------------------ 1 file changed, 6 insertions(+), 51 deletions(-) diff --git a/install.sh b/install.sh index 81ed296..0e9306f 100755 --- a/install.sh +++ b/install.sh @@ -333,61 +333,16 @@ networkConf() { unset hostname } -calcWidthDialog() { - str=$1; count=1; found=false; option=1 - for (( i = 0; i < ${#str}; i++ )); do - if [ "${str:$i:1}" = "\\" ] && [ "${str:$((i+1)):1}" = "n" ]; then - [ $count -ge $option ] && option=$count - found=true - count=-1 - fi - ((count++)) - done - [ $option -ge $count ] && count=option - echo $((count+3)) -} - -calcHeightDialog() { - newlines=$(printf "$1" | grep -c $'\n') - chars=$(echo "$1" | wc -c) - height=$(echo "$chars" "$newlines" | awk '{ - x = (($1 - $2 + ($2 * 60)) / 60) - printf "%d", (x == int(x)) ? x : int(x) + 1 - }') - echo $((4+height)) -} - -calcWidthAndRun() { +calcAndRun() { argc="$#"; i=1 for item in "$@"; do - if [ $i -eq $((argc-2)) ]; then - str="$item" - break - fi + [ $i -eq $((argc-2)) ] && str="$item" + [ "$item" = "WIDTH" ] && { function="calcWidthDialog"; dimName="width"; } + [ "$item" = "HEIGHT" ] && { function="calcHeightDialog"; dimName="height"; } ((i++)) done - width=$(calcWidthDialog "$str") - comm=$(echo "$@" | sed "s/WIDTH/$width/g") - if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then - comm="${comm} 3>&1 1>&2 2>&3" - fi - commOutput=$(eval "$comm") - exitStatus=$? - [ -n "$commOutput" ] && echo "$commOutput" - return $exitStatus -} - -calcHeightAndRun() { - argc="$#"; i=1 - for item in "$@"; do - if [ $i -eq $((argc-2)) ]; then - str="$item" - break - fi - ((i++)) - done - height=$(calcHeightDialog "$str") - comm=$(echo "$@" | sed "s/HEIGHT/$height/g") + dim=$($function "$str") + comm="${*//${dimName^^}/$dim}" if [[ $comm != *"3>&1 1>&2 2>&3" ]]; then comm="${comm} 3>&1 1>&2 2>&3" fi