#!/bin/sh
# 
# grepmail.sh, a wrapper script for the grepmail script to run grepmail
#              in a loop. Nice for use to run in a Multi Gnome Terminal 
#              Tab.
#
# Requires: grepmail script, which requires mboxgrep. banner.sh is optional.
#
# Note: Extra \ escapes are required to survive passing through various 
# shell levels. Use like: John\\\\sDoe, to have \s passed to mboxgrep.
#
# Hal Burgiss <hal@foobox.net>
#
######################################################################

myname=`basename $0`
# where to store command history, view with 'history' command.
history=/tmp/$myname-history
command="/home/hal/bin/multi-gnome-terminal-1.5.0/bin/multi-gnome-terminal --add-tab --tname SearchResults -x mgt-helper -s -t feenix grepmail"
msg1="$myname Welcomes $USER"
#msg2="  grepmail, a mboxgrep wrapper for searching multiple mailboxes, and"
#mgs3="  displaying the results"

while :; do

#  clear
  which banner.sh >/dev/null &&\
  banner.sh -r 2 -U "" -c "$msg1" " " ||\
  clear
  printf "Enter command line for grepmail to execute:\n\n" 
  read -ep "  grepmail: " exp

  if [ "$exp" = "q" -o "$exp" = "Q" ]; then
  # q to quit program.
    break
  elif [ "$exp" = "?" -o "$exp" = "help" ]; then
    clear ; printf "\n\n\n"
    grepmail --usage
    echo "     Press ENTER to continue ... "
    read -t 60
  elif [ "$exp" = "history" ]; then
   [ -f $history ] && less $history || read -t5 -p "  no history available"
  elif [ "$exp" = "" ]; then
    printf "\n\'q\' to quit\n\'history\' - to view command history\n\
\'help\' - to view brief grepmail usage info\n\n"  ; read -t5
  else
    printf "\n        "
    echo "$exp" >> $history
    $command "$exp"
  fi 

done

#--- eof grepmail.sh
