[comp.sources.d] "one-line" tinkertoy tree display

jaw@aurora.UUCP (James A. Woods) (12/09/86)

     Try this incredibly fiendish script on a directory name:

echo $1; find $1 -type d -print | tr / \\1 | sort -f | tr \\1 / |\
sed -e s,\^$1,, -e /\^$/d -e "s,[^/]*/\\([^/]*\\)\$, \`-----\\1," -e "s,[^/]*/, |     ,g"

     Thanks and a tip o' the hat to Doug Kerr of NASA Ames Research Center
(ames!doug).  Attached see the spoiler explanation from USENET of 1984.

-----
>From postnews Tue Dec 11 21:57:08 1984
Subject: directory tree display made simple
Newsgroups: net.unix,net.wanted.sources

#  George of the Jungle quote goes here.

     Someone asked about tree printing.  For the sub-problem of displaying
UNIX directory trees, there's always the one-liner (courtesy Doug Kerr of
Sterling Software Corp.)

	echo $1; find $1 -type d -print | tr / \\1 | sort -f | tr \\1 / |\
	sed -e s,\^$1,, -e /\^$/d -e "s,[^/]*/,	,g"

This just does directories -- if you want all files, take out the "-type d".
Explanation:  it works by substituting tabs for pathname slashes (the
invisible literal tab occurs before the ",g" above); the translits bracketing
the sort helps alphabetize '/' before [a-zA-Z].  And if you remember that 
other punctuation can replace the slash in ed/sed syntax (as the comma does in
the script), you needn't say "Deadhead Ed had edited it" fifty times fast.

     I find that anything which prints directory trees "vertically" is likely
to be complicated enough to have bugs, as well as being too screen-dependent.

     It will take some CPU time on big directory structures, but if one
runs the Ames Fast File Finder [ed. note -- a slow version of this appears in
BSD 4.3], it can be made near-instantaneous, though that's another story ...

     -- James A. Woods  (ames!jaw)