# Explanation of mk_fol_names Package

The Section Folder Name Variables gives an overview of this package. There are two scripts (mk_fol_names and mk_fol_names.install) and one data file (folder_table). You'll also be adding a line to your shell's setup file (like .login or .profile).

mk_fol_names

Here is the mk_fol_names script (you might want to open it in a separate browser window). To install it, see the Section Programs in This Book's Archive.

mk_fol_names is a script with many links (names). The mk_fol_names.install script creates all of these links for you after you've set up the folder_table. We'll see how to do that later.

Here's what mk_fol_names does. When you run the script, it checks its name (from the `$0` parameter) to decide which command to run and which folder name abbreviation to expand.

- If the name is csh_folders or sh_folders, the script outputs the folder table as a series of commands that set csh-style or sh-style shell variables.

  For example, with the default folder_table, calling the script as csh_folders would output the commands below. These commands are fed to your shell to set its folder-abbreviating shell variables:

            set mj = '+m/majordomo'
            set mju = '+m/to_read/majordomo-users'
               ...

- If the script is called with a name other than csh_folders or sh_folders, it assumes you want to run an MH command.

  The default folder_table has an abbreviation for mj. So, the script will have a link named fmj which refiles (f) into the folder abbreviated mj. Let's follow that example through the script and watch the MH command being built.

  Most of the script is actually just comment lines! The action starts with the sed command below (and some code above it). It stores the function name (here, f) in the shell variable func and the abbreviation (here, mj) in the shell variable abbrev:

            s/^\(.\)\(.*\)/func=\1 abbrev="\2"/p

  Next, the script checks `$func` to see what command to run. Here, the script sees that the leading f in the command name fmj stands for refile; it stores that command name in the cmd variable:

            case "$func" in
            a)  cmd=rfl ;;
            f)  cmd=refile ;;
            *)  echo "$0: Help!  Don't know how to run myself!" 1>&2; exit 1 ;;
            esac

  (The case statement above is where you customize the script to run commands other than the default refile and rfl.)

  Then the script looks up the abbreviation `$abbrev` in the folder table. `$T` holds a TAB character, so the sed expression matches a line starting with the current abbreviation (from `$abbrev`) followed by a TAB:

            fols=`sed -n "/^$abbrev$T/s///p" $table`

  Now `$fols` holds the expanded folder name (here, +m/majordomo). Finally, the command (`$cmd $fols`) is run. Here, that's `refile +m/majordomo`.

folder_table

The folder_table file has TAB-separated fields with a folder abbreviation followed by the folder(s) it stands for. Comment lines start with a hash mark (`#`).

You can store this file anywhere; its pathname is held by the table shell variable in the mk_fol_names and mk_fol_names.install scripts.

mk_fol_names.install

The mk_fol_names.install script must be run each time you add folder names to the folder_table file. This script reads the table and makes the links (like amj and fmj) that do the work. It also makes the links csh_folders and sh_folders to set the shell variable abbreviations.

If you customize mk_fol_names to understand commands with names that start in something other than a or f, you'll need to do the same to this script.

Your Shell's Setup File

To store shell variables, run csh_folders for csh and tcsh. Use sh_folders for sh, bash and ksh. (If you need some other syntax -- say, environment variables -- just modify the script and add a link to it.)

Run the command from your shell's startup file -- typically .cshrc for the C shell, .profile for the Bourne shell, and so on. For example, in the C shell:

        # Set shell variables with MH folder abbreviations:
        eval `csh_folders`

The backquotes (```) run csh_folders and leave its output (the commands to set the shell variables) as parameters for the eval command. The shell eval command re-scans and executes its parameters -- so, it sets the shell variables output by csh_folders.