#! /bin/sh
# $Id: fols,v 1.10 1996/07/08 02:20:21 jerry book3 $
### fols - Show list of folders, in columns, current folder marked
### Usage: fols [ -recurse ]  << (just -r is enough...)
##
##  THE folder -fast PROGRAM GIVES A LIST OF YOUR TOP-LEVEL FOLDERS
##  IN ONE COLUMN.  IF YOU HAVE A LOT OF FOLDERS, THIS CAN BE A PAIN
##  BECAUSE THE LIST CAN SCROLL OFF YOUR SCREEN.  fols REFORMATS THE
##  folder -fast OUTPUT INTO FOUR COLUMNS.  IT MARKS THE CURRENT FOLDER
##  WITH A +.  IF ANY FOLDER NAMES ARE TOO LONG FOR A COLUMN, IT
##  CUTS OUT THE MIDDLE OF THE NAME AND REPLACES IT WITH AN "=".
##
##  BY DEFAULT, fols ONLY SHOWS THE TOP-LEVEL FOLDERS.  THE -r SWITCH
##  MAKES IT RECURSIVE, LIKE folder -recurse -fast.
##
##  HERE'S AN EXAMPLE.  THE EXAMPLE WITH -r SHOWS A SET OF SUB-FOLDERS
##  NINE LEVELS DEEP, STARTING WITH A SUB-FOLDER NAMED test/l1:
##
##  % fols
##  drafts             haha               inbox+             scans
##  scantest           test               test2              test3
##  % fols -r
##  drafts             haha               haha/sub           inbox+
##  scans              scantest           test               test/MaIlSoRt9818
##  test/haha          test/l1            test/l1/l2         test/l1/l2/l3
##  test/l1/l2/l3/l4   test/l1/=/l3/l4/l5 test/l1/=/l4/l5/l6 test/l1/=/l5/l6/l7
##  test/l1/=/l6/l7/l8 test/l1/=/l7/l8/l9 test2              test3
# 
#                             NO WARRANTY
# 
#   BECAUSE THIS PROGRAM IS AVAILABLE FREE OF CHARGE, THERE IS NO WARRANTY
# FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
# OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
# PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
# OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
# TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
# PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
# REPAIR OR CORRECTION.
# 
#   IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
# WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
# REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
# INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
# OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
# TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
# YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
# PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGES.


folopts="-fast -nolist -nototal -nopack" # OVERRIDE MH PROFILE
rec=

case "$#$1" in
0"") ;;
1-r*) rec=-recurse ;;
*)  echo "Usage: `basename $0` [ -recurse ]" 1>&2; exit 1 ;;
esac

# USE BACKQUOTES TO "PASTE" THE CURRENT FOLDER NAME
# INTO THE sed EXPRESSION THAT ADDS A + TO END.
# THEN, IN ANY LINE WHICH HAS AT LEAST 19 CHARACTERS,
# SAVE FIRST 8 AND LAST 9 CHARACTERS AND REPLACE
# MIDDLE CHARACTER(S) WITH AN = SIGN.  FINALLY, GIVE
# TO pr WITH LINE LENGTH OF 1 TO MAKE INTO 4 COLUMNS:
folders $rec $folopts |
sed -e "s@^`folder $folopts`\$@&+@" \
    -e 's/^\(........\)...*\(.........\)$/\1=\2/' |
pr -l1 -4 -w78 -t
