#!/bin/bash

clear
if [ -z $1 ]
then
    echo "'doc' by Ben Okopnik - a /usr/doc info reader"
    echo
    echo "Usage: doc <xyz>"
    echo
    echo "'doc' will list all choices matching 'xyz*'."
    echo "More letters will produce a narrower query."
    echo
    exit 1
fi

pushd /usr/doc > /dev/null
cd $(select A in $1*; do echo $A; break; done)
clear

# Due to the unpredictable depth of directory structures 
# and the random number of retrievals, the loop below has to be
# infinite... which makes the exit method a crude one.

while [ 1 ]
do
    echo 'Press "Ctrl-C" when done.'
    echo '-------------------------'
    echo
    B=$(select C in *; do echo $C; break; done)
    if [ -d $B ]
    then
        cd $B
        clear
    else
        mc -v $B
    fi
done


