commentate pizza.sh

This commit is contained in:
ida schmidt 2023-04-26 02:06:00 -07:00
parent 9ab116d057
commit 9ca3fca632

View file

@ -1,7 +1,7 @@
#!/usr/bin/env bash
FSI=2.12206590789 # grams of Flour per Square Inch of pan
FSI=2.12206590789 # default grams of Flour per Square Inch of pan, fairly neopolitan
function pizzahelp {
function pizzahelp { # this only prints help text
echo "Pizza Calculator: The pizza script you never asked for"
echo
echo "Usage: ./pizza.sh [-h] [-f <N>] [<flour weight>g|<pan diameter>(in|inch|\")]"
@ -11,14 +11,14 @@ function pizzahelp {
echo
}
while getopts ":hf:" option; do
while getopts ":hf:" option; do # loop through options, casing them
case $option in
h)
pizzahelp
exit;;
f)
f) # the end result of changing this is to alter crust thickness
FSI=$OPTARG
shift 2;;
shift 2;; # the option and its arg will be in $1 and $2 if this is specified, so they have to be shifted out
\?)
echo "Error: Invalid option"
exit;;
@ -26,18 +26,18 @@ while getopts ":hf:" option; do
done
function panarea {
AREA=$(echo "3.1415926535*($DIAM/2)^2" | bc -l)
AREA=$(echo "3.1415926535*($DIAM/2)^2" | bc -l) # bc cant exponentiate non-integer bases without -l
SIZE=$(echo $AREA*$FSI | bc)
calcratio
}
function calcratio {
[ -n SIZE ] || read -p "Grams of flour: " SIZE
function calcratio { # this is mildly hacky
[ -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 '||')
LABEL=0
for RATIO in $(grep 'ratios' -A 8 pizza.txt | sed /\\[*.\\]/d | cut -f 2); do \
for RATIO in $(grep 'ratios' -A 8 pizza.txt | sed /\\[*.\\]/d | cut -f 2); do # finding [ratios] +8 tailing lines, removing the first.
((LABEL++))
grep 'ratios' -A 8 pizza.txt | sed /\\[*.\\]/d | cut -f 1 | sed $LABEL'!d'
echo $RATIO*$SIZE | bc
grep 'ratios' -A 8 pizza.txt | sed /\\[*.\\]/d | cut -f 1 | sed $LABEL'!d' # same deal but itterating through the labels
echo $RATIO*$SIZE | bc # actually print the calculated number for each label
done
# cleanup
unset LABEL
@ -48,7 +48,7 @@ function calcratio {
unset DIAM
}
case $1 in
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
*g)
SIZE=$(echo $1 | sed s/g//g)
calcratio;;