The fols Shell Script

[return-to Explanation of fols] [table of contents] [index]
#! /bin/sh
# $Id: fols,v 1.9 92/07/24 17:36:00 jerry book2 $
### 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
##
##  NOTE TO HACKERS: TABSTOPS ARE SET AT 4 IN THIS CODE

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@^`$mh/folder $folopts`\$@&+@" \
    -e 's/^\(........\)...*\(.........\)$/\1=\2/' |
pr -l1 -4 -w78 -t

[Table of Contents] [Index] [Return to Explanation of fols]


Last change $Date: 1996/06/06 15:13:46 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jpeek@jpeek.com>