4.7. Using Pantry with screen

Though Pantry may be used in conjunction with many other Unix shell utitlities, you may find GNU Screen to be particularly useful. screen is so useful with Pantry due to its advanced cutting-and-pasting capabilities. Here is a good introduction to screen. Most Linux systems will already have screen installed; if not, you'll be able to install it using your distribution's package manager.

Pantry includes the paste report, which makes screen particularly useful. Often in Pantry, you will be searching your master file, not entirely sure what food you are looking for. On other occasions, you will know what you are looking for, but your search terms return a lot of results to scroll through--and the food that you want has a very long name that you do not want to have to retype. Using the paste report, you can easily reuse your search results.

The paste report prints one line for each available unit for each food. The results include the -x, -n, and -U options, and the results are also quoted so you may easily paste them into a subsequent pantry command.

To see how powerful this is, we can return to our earlier example of finding how many calories are in an apple. You would likely start by searching the master file for the name trait apple. As we saw earlier, this returns 163 results:

Example 4.26. Searching for apple returns 163 results

$ pantry --ignore-case --name apple --print names master
Apple cider-flavored drink, powder, low calorie, with vitamin C, prepared
English muffins, raisin-cinnamon (includes apple-cinnamon)
Babyfood, cereal, high protein, with apple and orange, prepared with whole milk
Applesauce, canned, unsweetened, without added ascorbic acid
Pineapple, canned, light syrup pack, solids and liquids
Babyfood, fruit, bananas and pineapple with tapioca, strained
Babyfood, fruit, apple and raspberry,  junior
Apple juice, frozen concentrate, unsweetened, undiluted, with added ascorbic acid
Babyfood, apple-banana juice
Fruit salad, (peach and pear and apricot and pineapple and cherry), canned, extra heavy syrup, solids and liquids
Babyfood, fruit, apple and raspberry, strained
Pie fillings, apple, canned
Pineapple, frozen, chunks, sweetened
Scrapple, pork
Babyfood, fruit, bananas with apples and pears, strained
[ trimmed to save space ]

Earlier we limited our search results by typing subsequent pantry commands and tweaking the --name argument. When we zeroed in on the food we wanted, we typed yet another pantry command, this time to figure out the available units. Finally, we typed another pantry command to change the unit and quantity to what we wanted and to print the nutrient information for a single large apple.

You can do this using many fewer commands with screen and the paste report. After firing up screen, type a pantry for what you are looking for. I also use sort because I find it easier to scan results when they are alphabetized.

Example 4.27. Using the paste report

$ pantry --ignore-case --name apple --group fruit --print paste master | \
> sort
-x -n 'Apple juice, canned or bottled, unsweetened, with added ascorbic acid' -U 'cup' 
-x -n 'Apple juice, canned or bottled, unsweetened, with added ascorbic acid' -U 'fl oz' 
-x -n 'Apple juice, canned or bottled, unsweetened, with added ascorbic acid' -U 'g' 
-x -n 'Apple juice, canned or bottled, unsweetened, with added ascorbic acid' -U 'lb' 
-x -n 'Apple juice, canned or bottled, unsweetened, with added ascorbic acid' -U 'oz' 
-x -n 'Apple juice, canned or bottled, unsweetened, without added ascorbic acid' -U 'cup' 
-x -n 'Apple juice, canned or bottled, unsweetened, without added ascorbic acid' -U 'drink box (8.45 fl oz)' 
-x -n 'Apple juice, canned or bottled, unsweetened, without added ascorbic acid' -U 'fl oz' 
-x -n 'Apple juice, canned or bottled, unsweetened, without added ascorbic acid' -U 'g' 
-x -n 'Apple juice, canned or bottled, unsweetened, without added ascorbic acid' -U 'lb' 
-x -n 'Apple juice, canned or bottled, unsweetened, without added ascorbic acid' -U 'oz' 
-x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water, with added ascorbic acid' -U 'cup' 
-x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water, with added ascorbic acid' -U 'fl oz' 
-x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water, with added ascorbic acid' -U 'g' 
-x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water, with added ascorbic acid' -U 'lb' 
[ trimmed to save space ]

Now you can scroll through the results using Screen's commands; copy the line you are interested in to Screen's paste buffer. For more details on how to do this, consult the Screen manual page under "copy". Pay particular attention to the J command, which joins lines--this is useful if a particular line is so long that it does not fit on one line in your terminal.[10]

After finding the result you are interested in, you can easily paste it in to a new command line and add the options you need.



[10] You don't have to use screen; you can copy and paste using your terminal emulator if you wish. Though I think screen is easier to use, you might diasgree...