4.5. Pantry usage shortcuts

4.5.1. Using short options

For didactic purposes, all the examples in this manual use long-style options with two dashes. However, almost every pantry option is also available in short form. The search options (which search for a particular trait) and the change options (which change the traits of the foods in your result to a new value) have short options that conveniently differ only by their case. Thus, for example, -g searches by group name, and -G changes the group name.

If you need to jog your memory on what option does what, use the --help option. This option will also tell you which long options have corresponding short options.

In addition, when specifying reports, you may specify only the first few letters of the report name--enough letters to unambiguously specify the report name. For example, instead of typing --print names-nuts, you may instead type --print na-nu.

4.5.2. Learn your shell, and write scripts or functions to automate common tasks

As you have seen, pantry commands can get lengthy. That's one of the pitfalls of a command-line program. However, one of the great strengths of a command-line program is that you can easily write your own shell scripts or functions to automate commands you type frequently. In addition, shells have a wealth of features, such as history searching and command-line editing, that will speed up your shell usage. This will help you not only in Pantry but in other command-line tools as well.[9]

If you will use Pantry frequently, one of the things you will find most helpful is to write a script or function that will add new foods to a diary file. Such a script can, for example, automatically use the --c-date option to change the food so that it has today's date, or automatically use the --c-meal option. You might also write scripts or functions to easily produce reports using the --print options you use most frequently.

The most popular shell today is bash, which is very featureful. If you have never written a shell script or function before, take a look at the Bash Guide for Beginners.

You may also wish to consider using a shell other than Bash. For a very well-documented shell that is easier to learn than bash, consider fish, the Friendly Interactive Shell. For a very powerful shell with excellent documentation, try zsh.

Finally, whether you use Bash or Zsh, I highly recommend getting a copy of From Bash to Z Shell: Conquering the Command Line by Kiddle, Peek, and Stephenson. It clearly explains many of the features of shells, such as command history and completion, that make interactive use much easier and faster. Unlike most texts on shells, this one focuses on interactive use. It is well worth the price.

4.5.3. Learn other Unix utilities

Because you use Pantry from your standard command shell, you can easily combine Pantry with other Unix utilities, in ways that even I cannot anticipate. Most obviously, you will often use Pantry with less so that you may easily scroll through reports. You might also find yourself using sort, cut or even awk. The possibilities are endless.



[9] Pantry used to include a script called pantry-addTo that helps cut typing. However, in release 18 I removed it from Pantry. pantry-addTo was difficult to document because it is a personal hack that does not nearly conform to any interface standards. Personal hacks are wonderful for personal use, but they shouldn't be distributed for others. Thus, feel free to write your own personal hacks that will work perfectly for you.