#!/usr/local/bin/perl
#  Time-stamp: "2005-08-19 01:29:30 ADT"  sburke@cpan.org
# desc{   shows a directory structure   }
#
# Show the directory structure under given filespecs,
#  or under ./, if none given

use strict;
use File::Find;
use Getopt::Std;
use Text::Wrap;

my $e = {};
getopts('R', $e);

my $ind;

@ARGV = ('.') unless @ARGV;
my @out;
foreach my $x (@ARGV) {
  $x =~ s</+$><>s unless length $x == 1;
  $ind = $x =~ tr</><>;
  print "$x\n";
  find $e->{'R'} ? \&wanted_R : \&one_level,   $x;
  print wrap('  ', '  ', join(' ', @out)), "\n" if @out;
}
exit;

sub wanted_R {
  return if $_ eq '.';
  print '  ' x ($File::Find::name =~ tr</><> - $ind), $_, "\n"
    if lstat($_) && -d _;
}

sub one_level {
  return if $_ eq '.';
  return unless lstat($_) && -d _;
  my $d = ($File::Find::name =~ tr</><> - $ind);
  $File::Find::prune = 1 if $d;

  push @out, $_;
  #print '  ' x $d, " $_ $d $File::Find::name\n";
}

__END__
