Compare commits

...

3 Commits

Author SHA1 Message Date
ida schmidt c62e20d251 rename DIAM to WIDTH 2023-08-15 22:00:24 -07:00
ida schmidt 04f185051d better config file name 2023-08-15 21:20:16 -07:00
ida schmidt d650fcc1ae allow longer ingredient names 2023-08-15 21:19:02 -07:00
1 changed files with 13 additions and 13 deletions

View File

@ -27,10 +27,10 @@ function pizzahelp { # this only prints help text
echo
}
if [ -a "${XDG_CONFIG_HOME}/pizzacalc/pizza.txt" ]; then
ALTPIZZA="${XDG_CONFIG_HOME}/pizzacalc/pizza.txt"
elif [ -a "$HOME/.config/pizzacalc/pizza.txt" ]; then
ALTPIZZA="${HOME}/.config/pizzacalc/pizza.txt"
if [ -a "${XDG_CONFIG_HOME}/pizzacalc/conf" ]; then
ALTPIZZA="${XDG_CONFIG_HOME}/pizzacalc/conf"
elif [ -a "$HOME/.config/pizzacalc/conf" ]; then
ALTPIZZA="${HOME}/.config/pizzacalc/conf"
else
ALTPIZZA=/dev/null
fi
@ -64,9 +64,9 @@ done
shift $((OPTIND-1)) # shift options out from infront of the command to leave only arugment in $@
function panarea {
DFSI=$(cat "$INSTDIR/pizza.txt" | cat - "$ALTPIZZA" | grep -A 1 "\[$RECIPE:ratios\]" | tail -n -1 | cut -f 2) # find recipe's default flour per squre inch
DFSI=$(cat "$INSTDIR/pizza.txt" | cat - "$ALTPIZZA" | grep -A 1 "\[$RECIPE:ratios\]" | tail -n -1 | cut -f 2-) # find recipe's default flour per squre inch
FSI="${FSI:-$DFSI}" # dont use default fsi if already set
AREA=$(echo "3.1415926535*($DIAM/2)^2" | bc -l) # bc cant exponentiate non-integer bases without -l
AREA=$(echo "3.1415926535*($WIDTH/2)^2" | bc -l) # bc cant exponentiate non-integer bases without -l
SIZE=$(echo "$COUNT"*$AREA*"$FSI" | bc -l)
arraytio
}
@ -74,7 +74,7 @@ function panarea {
function arraytio { # im funny portmantaus are never bad
[ -n SIZE ] || read -p "Grams of flour: " SIZE # test ([) will send a non-zero exit code on if $SIZE doesnt exist, tripping the or (the '||')
INDEX=0
for RATIO in $(cat "$INSTDIR/pizza.txt" | cat - "$ALTPIZZA" | sed -n "/\[$RECIPE:ratios\]/,/^$/p" | tail -n +3 | cut -f 2); do # finding [ratios] until the next blank line, removing the first two lines.
for RATIO in $(cat "$INSTDIR/pizza.txt" | cat - "$ALTPIZZA" | sed -n "/\[$RECIPE:ratios\]/,/^$/p" | tail -n +3 | cut -f 2-); do # finding [ratios] until the next blank line, removing the first two lines.
declare -a INGREDIENT # make arrays
declare -a MEASURE
((INDEX++)) # increment the index
@ -88,7 +88,7 @@ function arraytio { # im funny portmantaus are never bad
unset SIZE
unset FSI
unset AREA
unset DIAM
unset WIDTH
}
case $1 in # this parses the first argument (and actually calls our main functions), the units need to be removed before bc will accept it
@ -96,17 +96,17 @@ case $1 in # this parses the first argument (and actually calls our main functio
SIZE=$(echo $1 | sed s/g//g)
arraytio;;
+([0-9])?(.)*([0-9])\")
DIAM=$(echo $1 | sed s/\"//g)
WIDTH=$(echo $1 | sed s/\"//g)
panarea;;
+([0-9])?(.)*([0-9])inch)
DIAM=$(echo $1 | sed s/inch//g)
WIDTH=$(echo $1 | sed s/inch//g)
panarea;;
+([0-9])?(.)*([0-9])in)
DIAM=$(echo $1 | sed s/in//g)
WIDTH=$(echo $1 | sed s/in//g)
panarea;;
*)
read -p "Diameter of pan (in inches): " DIAM
DFSI=$(cat "$INSTDIR/pizza.txt" | cat - "$ALTPIZZA" | grep -A 1 "\[$RECIPE:ratios\]" | tail -n -1 | cut -f 2)
read -p "Diameter of pan (in inches): " WIDTH
DFSI=$(cat "$INSTDIR/pizza.txt" | cat - "$ALTPIZZA" | grep -A 1 "\[$RECIPE:ratios\]" | tail -n -1 | cut -f 2-)
read -p "Flour per square inch [$DFSI]: " FSI
panarea;;
esac