Article View: comp.unix.programmer
Article #3351simple text outline processor script
From: Rick Hohensee
Date: Tue, 19 Feb 2002 04:12
Date: Tue, 19 Feb 2002 04:12
92 lines
4886 bytes
4886 bytes
# cLIeNUX outline Public Domain
# Due to the way I've probably pasted this into my mailer,
# if you got this off the net as text you may need to convert some
# spaces to tabs. ,s/^/$indent / and indent=$indent" "
# below each have one tab... ^^^^\tab tab/^
user=~
if test $# -eq 0 ; then
echo "
You didn't give outline any directory arguments. That's not so awful,
but it's a handy case to stick this help response on.
cLIeNUX outline allows a hierarchical filesystem to be used as a
rudimentry outline processor. outline doesn't generate nested section
tags, like A.3.c or what have you. It does indenting and
directory-names-as-headings. You can have a dedicated outline, or extract
one from something with some larger purpose. outline makes a single
outline-indented textfile from all the textfiles in the directory tree(s)
given to it as a(n) argument(s). As initially implemented, a text file is
any file that the unix utility \"file\" describes with words including
the string \"text\". This includes html, C sourcecode and so on. For
example, cLIeNUX's version of \"file\" reports
HTML document text
when it thinks it found html, so the
outline generated will include such html files. The outline file will be
found as ~/outline when outline is done. Due to the hackness of that
little expedient, one user can only sensibly generate one outline on a
machine at a time, which I don't expect to be terribly problematic.
Run outline on a directory tree with a lot of commands in it, and you
should get an outline containing all the scripts and docs.
cLIeNUX also has the more general \"walk\" directory recurser script.
"
else
TOLrecurse () {
local f
for f in $* ;do
if test ! -L $f -a ! -d $f ; then
if file $f | grep text > /dev/null ;then
echo "$indent$f FILE " >> $user/outline
ed $f <<!
,s/^/$indent /
,W $user/outline
q
!
fi
fi
if test -d $f -a ! -L $f; then
echo "$indent$f ### DIRECTORY " >> $user/outline
indent=$indent" "
cd $f
TOLrecurse *
cd ..
indent=${indent:0:${#indent}-1}
fi
done
}
rm $user/outline
TOLrecurse $*
fi
#As far as a sh besides Bash, the tricky stuff outline needs from a shell is
#parameter expansions capable of an action like Perl's chomp, which is
# a variously skinnable cat, and recursive instantiation of locals, which
# latter I think even ash does. As to chomp, you can keep the indent
# with a case and a nesting count, thus not needing chomp, for example.
#outline is dependant on GNU Bash, ed, file, and grep, and /dev/null.
#outline is a small script and lends itself to specialized mods, except
#that it's recursive, and thus is tricky code flow-control-wise, but if you
#just change test cases and stuff it should be fun and quite handy for the
#non-theoretically-inclined.
# LAAETTR...
# write-a-book version
# brief outline version, N lines limit per file (3 more characters
# in the ed part... 1,10W )
# suffix-based for C, include .c and .s but not .i or .o
# webtangler version
# Linux help version
# nested section tags generation/propagation
# do something cute with symlinks
# yadda yadda
# Copyright 2002 Rick Hohensee
Technical Details
Message-ID:
<aed9cc15.0202182012.4aab38ee@posting.google.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1054c0,5c167cf03c441214,start X-Google-Attributes: gid1054c0,public X-Google-Thread: fc89c,5c167cf03c441214,start X-Google-Attributes: gidfc89c,public X-Google-Thread: 1103af,5c167cf03c441214,start X-Google-Attributes: gid1103af,public X-Google-Thread: 111b49,5c167cf03c441214,start X-Google-Attributes: gid111b49,public X-Google-ArrivalTime: 2002-02-18 20:12:45 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!postnews1.google.com!not-for-mail From: rickh@capaccess.org (Rick Hohensee) Newsgroups: comp.unix.programmer,gnu.bash,comp.os.linux.misc,fa.linux.kernel Subject: simple text outline processor script Date: 18 Feb 2002 20:12:43 -0800 Organization: http://groups.google.com/ Lines: 92 Message-ID: <aed9cc15.0202182012.4aab38ee@posting.google.com> NNTP-Posting-Host: 64.26.65.66 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: posting.google.com 1014091964 748 127.0.0.1 (19 Feb 2002 04:12:44 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: 19 Feb 2002 04:12:44 GMT