4.6. Using Pantry with screen
Prev | Chapter 4. More Pantry usage | Next

## 4.6. 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.[10]

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.20. Searching for `apple` returns 163 results

    $ pantry --ignore-case --name apple --print names master
    Babyfood, fruit, bananas and pineapple with tapioca, junior
    Apples, canned, sweetened, sliced, drained, heated
    Fast foods, burrito, with fruit (apple or cherry)
    Babyfood, fruit, applesauce and apricots, strained
    Cereals ready-to-eat, GENERAL MILLS, OATMEAL CRISP, APPLE CINNAMON
    HEALTHY CHOICE Country Roasted Turkey w/Cranberry Apple Sauce, Green Beans & Carrot Blend
    Danish pastry, fruit, enriched (includes apple, cinnamon, raisin, lemon, raspberry, strawberry)
    Pineapple, canned, water pack, solids and liquids
    PEPPERIDGE FARM Apple Turnovers, frozen, ready to bake
    Babyfood, fruit, bananas with apples and pears, strained
    Apples, dried, sulfured, stewed, with added sugar
    Apples, raw, with skin
    Fruit cocktail, (peach and pineapple and pear and grape and cherry), canned, extra light syrup, solids and liquids
    Babyfood, juice, apple-sweet potato
    Babyfood, apple-banana juice
    [ 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 command for what you are looking for.

Example 4.21. Using the `paste` report

    $ pantry --ignore-case --name apple --group fruit --print paste --sort n \
    > master
    -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 'fl oz'
    -x -n 'Apple juice, canned or bottled, unsweetened, with added ascorbic acid' -U '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 'cup'
    -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 'g'
    -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 'oz'
    -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, frozen concentrate, unsweetened, diluted with 3 volume water without added ascorbic acid' -U 'lb'
    -x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water without added ascorbic acid' -U 'fl oz'
    -x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water without added ascorbic acid' -U 'oz'
    -x -n 'Apple juice, frozen concentrate, unsweetened, diluted with 3 volume water without added ascorbic acid' -U 'g'
    [ 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.[11]

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] Actually, the results are quoted so they may be pasted into shells that have Bourne-like syntax, such as bash, zsh, and fish. I don't know enough about csh-like shells to know if the `paste` report works with them.

[11] 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...

Prev | Up | Next
4.5. Pantry usage shortcuts | Home | 4.7. Multilingual Pantry