Finish dynamic calc

This commit is contained in:
Santiago Lo Coco 2021-12-30 23:18:31 -03:00
parent 3af5518f39
commit 2a320b9101
2 changed files with 32 additions and 19 deletions

View File

@ -47,14 +47,14 @@ getGitconfigData() {
displayDialogBox --yesno "Would you like to set up gitconfig?" || return
displayDialogBox --msgbox "Now, I will ask you for data to set up gitconfig personal account."
gitPersonalName=$(displayDialogBox --inputbox "Enter a name." 3>&1 1>&2 2>&3)
gitPersonalMail=$(displayDialogBox --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3)
gitPersonalName=$(displayDialogBox --inputbox "Enter a name." VALUES 3>&1 1>&2 2>&3)
gitPersonalMail=$(displayDialogBox --inputbox "Enter an e-mail." VALUES 3>&1 1>&2 2>&3)
while true; do
displayDialogBox --yesno "Please confirm that the data you entered is correct:\n\n - Name: ${gitPersonalName}\n - E-mail: ${gitPersonalMail}"
[ $? -eq 1 ] || break
gitPersonalName=$(displayDialogBox --inputbox "Enter a name." 3>&1 1>&2 2>&3)
gitPersonalMail=$(displayDialogBox --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3)
gitPersonalName=$(displayDialogBox --inputbox "Enter a name." VALUES 3>&1 1>&2 2>&3)
gitPersonalMail=$(displayDialogBox --inputbox "Enter an e-mail." VALUES 3>&1 1>&2 2>&3)
done
displayDialogBox --yesno "Would you like to set up a work account?"
@ -63,19 +63,19 @@ getGitconfigData() {
return
fi
gitWorkPath=$(displayDialogBox --inputbox "Enter an absolute folder path where you would like to use the work account." 3>&1 1>&2 2>&3)
gitWorkPath=$(displayDialogBox --inputbox "Enter an absolute folder path where you would like to use the work account." VALUES 3>&1 1>&2 2>&3)
while [[ ! -d $gitWorkPath ]]; do
[ $? -eq 1 ] || break
gitWorkPath=$(displayDialogBox --inputbox "Path isn't valid. Please try again" 3>&1 1>&2 2>&3)
gitWorkPath=$(displayDialogBox --inputbox "Path isn't valid. Please try again" VALUES 3>&1 1>&2 2>&3)
done
gitWorkName=$(displayDialogBox --inputbox "Enter a name." 3>&1 1>&2 2>&3)
gitWorkMail=$(displayDialogBox --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3)
gitWorkName=$(displayDialogBox --inputbox "Enter a name." VALUES 3>&1 1>&2 2>&3)
gitWorkMail=$(displayDialogBox --inputbox "Enter an e-mail." VALUES 3>&1 1>&2 2>&3)
while true; do
displayDialogBox --yesno "Please confirm that the data you entered is correct:\n\n - Name: ${gitWorkName}\n - E-mail: ${gitWorkMail}"
[ $? -eq 1 ] || break
gitWorkName=$(displayDialogBox --inputbox "Enter a name." 3>&1 1>&2 2>&3)
gitWorkMail=$(displayDialogBox --inputbox "Enter an e-mail." 3>&1 1>&2 2>&3)
gitWorkName=$(displayDialogBox --inputbox "Enter a name." VALUES 3>&1 1>&2 2>&3)
gitWorkMail=$(displayDialogBox --inputbox "Enter an e-mail." VALUES 3>&1 1>&2 2>&3)
done
sed -e "s/PERSONAL_NAME/$gitPersonalName/g" -e "s/PERSONAL_MAIL/$gitPersonalMail/g" -e "s|WORK_PATH|${gitWorkPath}|g" ./templates/.gitconfig > ./dotfiles/.gitconfig

View File

@ -29,25 +29,38 @@ useDialog() {
useWhiptail() {
str="${@: -1}"
if [ "$str" = "VALUES" ]; then
argc="$#"; i=1
for item in "$@"; do
if [ $i -eq $((${argc}-1)) ]; then
str="$item"
break
fi
((i++))
done
fi
width=$(calcWidth "$str")
height=$(calcHeight "$str")
whiptail "$@" ${height} ${width}
formatOptions "$@"
if [ $found = false ]; then
height=0; width=0
whiptail "$@" ${height} ${width}
else
whiptail "${options[@]}"
fi
}
formatOptions() {
options=()
options=(); found=false
for item in "$@"; do
if [ "$item" = "VALUES" ]; then
options+=("${height}")
options+=("${width}")
found=true
continue
fi
if echo "$item" | grep -q "[0-9]" || echo "$item" | grep -q "[--]"; then
options+=("${item}")
else
options+=("\"${item}\"")
fi
options+=("${item}")
done
}
@ -75,7 +88,7 @@ calcHeight() {
x = (($1 - $2 + ($2 * 60)) / 60)
printf "%d", (x == int(x)) ? x : int(x) + 1
}')
echo $((5+${height}))
echo $((6+${height}))
}
setDialogBox() {