reorganize function definitions to all be in the same place
This commit is contained in:
parent
9944680137
commit
4ff5e3589b
1 changed files with 38 additions and 38 deletions
76
pizza.sh
76
pizza.sh
|
@ -4,6 +4,44 @@ variation="${variation:-hand}"
|
|||
count="${count:-1}"
|
||||
shopt -s extglob
|
||||
|
||||
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 # not sure how compatable this is as a fallback? maybe use /dev/null ?
|
||||
altpizza=-
|
||||
fi
|
||||
|
||||
recipe="${recipe:-$(cat "$instdir/pizza.txt" | cat "$altpizza" - | grep -m1 ratios | cut -d ':' -f1 | sed 's/\[//')}"
|
||||
|
||||
while getopts ":hiv:r:f:c:" option; do # loop through options, casing them
|
||||
case $option in
|
||||
h)
|
||||
pizzahelp
|
||||
exit;;
|
||||
i)
|
||||
pizzarecipe
|
||||
exit;;
|
||||
f) # the end result of changing this is to alter crust thickness
|
||||
fsi="$OPTARG";;
|
||||
v) # change variation (usually between hand and standmixer)
|
||||
variation="$OPTARG";;
|
||||
r) # change dough recipe
|
||||
recipe="$OPTARG";;
|
||||
c) # change the number of pizzas the dough can be split into
|
||||
count="$OPTARG";;
|
||||
\?)
|
||||
echo "Error: Invalid option"
|
||||
exit;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1)) # shift options out from infront of the command to leave only arugment in $@
|
||||
|
||||
function pizzarecipe {
|
||||
echo "How to make the $recipe calculator pizza, $variation edition:"
|
||||
cat "$instdir/pizza.txt" | cat "$altpizza" - | sed -n -E "/\[$recipe:instructions(:$variation)?\]/,/^$/p" | sed '/\[*.\]/d'
|
||||
}
|
||||
|
||||
function pizzahelp { # this only prints help text
|
||||
echo "Pizza Calculator: The pizza script you never asked for"
|
||||
echo
|
||||
|
@ -27,44 +65,6 @@ function pizzahelp { # this only prints help text
|
|||
echo
|
||||
}
|
||||
|
||||
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 # not sure how compatable this is as a fallback? maybe use /dev/null ?
|
||||
altpizza=-
|
||||
fi
|
||||
|
||||
recipe="${recipe:-$(cat "$instdir/pizza.txt" | cat "$altpizza" - | grep -m1 ratios | cut -d ':' -f1 | sed 's/\[//')}"
|
||||
|
||||
function pizzarecipe {
|
||||
echo "How to make the $recipe calculator pizza, $variation edition:"
|
||||
cat "$instdir/pizza.txt" | cat "$altpizza" - | sed -n -E "/\[$recipe:instructions(:$variation)?\]/,/^$/p" | sed '/\[*.\]/d'
|
||||
}
|
||||
#TODO: use getopt
|
||||
while getopts ":hiv:r:f:c:" option; do # loop through options, casing them
|
||||
case $option in
|
||||
h)
|
||||
pizzahelp
|
||||
exit;;
|
||||
i)
|
||||
pizzarecipe
|
||||
exit;;
|
||||
f) # the end result of changing this is to alter crust thickness
|
||||
fsi="$OPTARG";;
|
||||
v) # change variation (usually between hand and standmixer)
|
||||
variation="$OPTARG";;
|
||||
r) # change dough recipe
|
||||
recipe="$OPTARG";;
|
||||
c) # change the number of pizzas the dough can be split into
|
||||
count="$OPTARG";;
|
||||
\?)
|
||||
echo "Error: Invalid option"
|
||||
exit;;
|
||||
esac
|
||||
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
|
||||
fsi="${fsi:-$dfsi}" # dont use default fsi if already set
|
||||
|
|
Loading…
Add table
Reference in a new issue