[PLUG] tree to html

Jeme A Brelin jeme at brelin.net
Fri Dec 13 03:30:04 UTC 2002


On Thu, 12 Dec 2002, Kyle Accardi wrote:
> ...or unix tinker toys
> 
> Trying to write a bash script (perl solutions will not be suffered)
> that will htmlize a directory listing in a nice tree-like way.

Well, perl is THE unix tinker toy, but if you don't want to do things the
easy way...

> First approach used `find` and if the filename wasn't a directory, I
> echoed a few &nbsp's to indent it.  But when your directory has more
> than two levels, that approach falls appart and you are looking at
> keeping track of how deeply you are nested so you can output the
> proper indentation.  Gnarly stack ops in bash dude.  Some other day.

It seems like you could just use `find .` and check to see if the current
output string is a substring of the following output string and if so
store it as $CURRENT_DIR and indent appropriately moving down the
tree.  You could use sed to split on the / and see what comes out that
way, too.

It all seems rather complex when perl and tree do it fairly nicely.

> So, Plan B:
> Htmlize the output from `tree`.

Did you try `tree -H`?  Was that just not what you needed?

You could modify the source so that -H puts out something more like what
you wanted.  I'm not a master C programmer and I took a look and saw that
I could do it without too much effort at all.

> QUESTION:  Is there a better tool to A) Provide a tree-like output, and

I think modifying tree to give what you want is probably the easiest
route.

> 2)  substitute strings instead of single chars.
> 
> If I could substitute "|--" with "&nbsp", I'd be a little happier.

It's called sed, sir.

J.
-- 
   -----------------
     Jeme A Brelin
    jeme at brelin.net
   -----------------
 [cc] counter-copyright
 http://www.openlaw.org





More information about the PLUG mailing list