The pantry-addTo command is a
front-end to the pantry command.
If you use it you can type, for instance,
ab banana
to add a banana to
today's breakfast.
pantry-addTo does this by
examining the name of the file used to call it. In
the above example, ab
is a
symlink to pantry-addTo.
pantry-addTo "knows"
that ab
means "add to
breakfast".
Here is how to configure pantry-addTo:
In your .pantryrc.xml
file,
add an element called
pantry-addTo
. Add one empty
symlink
element for each
symlink you wish to use. The
symlink
element has two
attributes. filename
is the
name of the symlink you will be using. It is
only the basename of the symlink--that is, it is
not the full pathname. The other attribute,
meal
, is the meal that will
correspond to this symlink.
Add two more elements to your
.pantryrc.xml
file inside the
pantry-addTo
element.
source
specifies which
file the foods will be copied from. It is a
child to the pantry-addTo
element and has one attribute,
filename
, which is the
respective filename. You will
probably find it easiest to use
pantry-addTo if you
specify a source
that has
only foods you use frequently, as we
discussed earlier in Section 3.3.1, “A quick
file”.
You will also need a
destination
element,
which specifies where new foods will be
copied to. As with the source
element, this element has a single attribute
named filename
.
In the following example,
ab
will add a food and
change its Meal
trait
to Breakfast
;
al
will add a food and
change its Meal
trait to
Lunch
, and so on.
pantry-addTo will search the
file
/home/massysett/pantry/quick
for foods, and the changed foods will be added
to
/home/massysett/pantry/diary
.
Example 4.22. Example .pantryrc.xml file with pantry-addTo configuration
<pantryrc> <path dir='.' /> <path dir='/home/massysett/pantry' /> <default-nutrient-list name='facts' /> <nutrient-list name='eatless'> <nutrient name='Calories' units='kcal' goal='1800' /> <nutrient name='Total Fat' units='g' goal='40' /> <nutrient name='Protein' units='g' goal='90' /> <nutrient name='Total Carbohydrate' units='g' goal='270' /> <nutrient name='Calcium' units='mg' /> </nutrient-list> <sort-order trait='meal'> <item value='Breakfast' /> <item value='Lunch' /> <item value='Dinner' /> </sort-order> <pantry-addTo> <symlink filename='ab' meal='Breakfast' /> <symlink filename='al' meal='Lunch' /> <symlink filename='ad' meal='Dinner' /> <symlink filename='ab-dev' meal='Breakfast' /> <symlink filename='al-dev' meal='Lunch' /> <symlink filename='ad-dev' meal='Dinner' /> <source filename='/home/massysett/pantry/quick' /> <destination filename='/home/massysett/pantry/diary.txt' /> </pantry-addTo> </pantryrc>
Finally, create symlinks for each meal you specified
in your .pantryrc. The link target is your
pantry-addTo
file, while the link
name is the short name you specified in
pantry-addTo
. The symlinks will be
easiest to use if they are in a directory that is in
your PATH.
Using pantry-addTo is simple.
Type the appropriate program name (such as
ab in my example) followed by
at least one, but no more than three, arguments.
The first argument must be a regular
expression that will search the
name
traits in the file you
specified in source
. The
second argument, which is optional, is a
quantity that you wish to change the quantity
trait of your search results to. The third
argument, also optional, is a unit argument,
used to change the units of your search results
if you wish. pantry-addTo
will automatically print the traits of the foods
it finds, after their traits have been changed.
Some further notes about using pantry-addTo:
All searches are case insensitive.
By default, pantry-addTo
searches the name
traits of
the search file. Use the -g
or
--group
option to search the
group
traits instead.
There is an -R
option that
corresponds to the pantry
option by the same name.
pantry-addTo
always uses the
--auto-order
option.
pantry-addTo
automatically sets the date
trait of foods to today's date.
pantry-addTo automatically prints the traits of the foods that it finds before adding them.
Here is an example of how to use
pantry-addTo. First, it is best to
use pantry-addTo with a
quick
file, so we will set one up
first.
Example 4.23. Setting up a quick
file
$
pantry --ignore-case --name "apples, raw, with skin" --c-qty \
>
1 --c-unit large --add quick master
$
pantry --ignore-case --name "kellogg's corn flakes" \
>
--c-qty 1 --c-group "Cereal and Milk" --c-unit cup --add \
>
quick master
$
pantry --ignore-case --name "milk, reduced fat, fluid, 2% \
>
milkfat, with added vitamin A" --c-group "Cereal and \
>
Milk" --c-qty 1 --c-unit cup --add quick master
$
pantry --ignore-case --name "carrots, raw" --c-qty 1 \
>
--c-unit ^large --add quick master
$
pantry --ignore-case --name 'chicken.*wing, meat and skin, \
>
cooked, roasted' --c-unit wing --c-qty 3 --add quick master
$
pantry --ignore-case --name "ice creams, chocolate, rich" \
>
--c-qty 1 --c-unit cup --add quick master
$
pantry --ignore-case --name "mcdonald's, cheeseburger" \
>
--c-unit item --c-qty 1 --add quick master
$
pantry --ignore-case --name "mcdonald's, french fries" \
>
--c-qty 1 --c-unit large --add quick master
$
pantry --ignore-case --name "popcorn, oil-popped, unsalted" \
>
--c-qty 2 --c-unit oz --add quick master
Now let's assume that you have set up your
.pantryrc.xml
and symlinks as we
described above.
Example 4.24. Using pantry-addTo scripts
$
ab apples
Apples, raw, with skin Group: Fruits and Fruit Juices Date: 2007-07-20 Meal: Breakfast Refuse: 8 percent Core and stem 1 large (3-1/4" dia) (approx 2 per lb) (212g)
$
ab -g "Cereal and Milk"
Cereals ready-to-eat, KELLOGG, KELLOGG'S Corn Flakes Group: Cereal and Milk Date: 2007-07-20 Meal: Breakfast 1 cup (1 NLEA serving) (28g) Milk, reduced fat, fluid, 2% milkfat, with added vitamin A Group: Cereal and Milk Date: 2007-07-20 Meal: Breakfast 1 cup (244g)
$
al carrots 3 small
Carrots, raw Group: Vegetables and Vegetable Products Date: 2007-07-20 Meal: Lunch Refuse: 11 percent Crown, tops and scrapings 3 small (5-1/2" long) (150g)
$
al -R chicken 10 '^oz$'
Chicken, broilers or fryers, wing, meat and skin, cooked, roasted Group: Poultry Products Date: 2007-07-20 Meal: Lunch Refuse: 48 percent Bone 5.2 oz (147g)
$
ad cheeseburger 2
McDONALD'S, Cheeseburger Group: Fast Foods Date: 2007-07-20 Meal: Dinner 2 item (238g)
$
ad popcorn
Snacks, popcorn, oil-popped, unsalted Group: Snacks Date: 2007-07-20 Meal: Dinner 2 oz (57g)
Finally, let's see the results. Here we pair
pantry with date
to show only foods that match today's date in the
diary
file.
Example 4.25. Seeing the results from using pantry-addTo
$
pantry --date `date +%F` --sort mo --print traits-blank-sum diary
Apples, raw, with skin Group: Fruits and Fruit Juices Date: 2007-07-20 Meal: Breakfast Order: 0010 Refuse: 8 percent Core and stem 1 large (3-1/4" dia) (approx 2 per lb) (212g) Cereals ready-to-eat, KELLOGG, KELLOGG'S Corn Flakes Group: Cereal and Milk Date: 2007-07-20 Meal: Breakfast Order: 0020 1 cup (1 NLEA serving) (28g) Milk, reduced fat, fluid, 2% milkfat, with added vitamin A Group: Cereal and Milk Date: 2007-07-20 Meal: Breakfast Order: 0030 1 cup (244g) McDONALD'S, Cheeseburger Group: Fast Foods Date: 2007-07-20 Meal: Dinner Order: 0010 2 item (238g) Snacks, popcorn, oil-popped, unsalted Group: Snacks Date: 2007-07-20 Meal: Dinner Order: 0020 2 oz (57g) Carrots, raw Group: Vegetables and Vegetable Products Date: 2007-07-20 Meal: Lunch Order: 0010 Refuse: 11 percent Crown, tops and scrapings 3 small (5-1/2" long) (150g) Chicken, broilers or fryers, wing, meat and skin, cooked, roasted Group: Poultry Products Date: 2007-07-20 Meal: Lunch Order: 0020 Refuse: 48 percent Bone 5.2 oz (147g) SUM: Nutrient Amount %G ----------------------------------------------- Calories 1744 kcal 87 Total Fat 78 g 121 Saturated Fat 25 g 123 Cholesterol 227 mg 76 Sodium 2021 mg 84 Total Carbohydrate 179 g 60 Dietary Fiber 18 g 73 Sugars 60 g NG Protein 87 g 175 Vitamin A 27192 IU 544 Vitamin C 27 mg 45 Calcium 774 mg 77 Iron 18 mg 100