#!/usr/bin/perl -w

$verzeichnis = '/home/loescher/media/diashow';
$einrueckung = ' ' x 5;

if ($ARGV[0] eq '--test')
{
  shift;
  $test = 1;
}

chdir($verzeichnis) || die "Verzeichnis $verzeichnis existiert nicht!\n";

if ($test)
{
  @shows = sort(`find . -type f -maxdepth 1 | xargs grep -l diashow | grep -v \~ | grep -- -test\$ | grep -v copy-files`);
}
else
{
  @shows = sort(`find . -type f -maxdepth 1 | xargs grep -l diashow | grep -v \~ | grep -v -- -test\$ | grep -v copy-files`);
}

$i = 0;
system("clear");
print "\n";
foreach $show (@shows)
{
  $i++;
  chomp($show);
  $show =~ s:./::;
  print $einrueckung . sprintf("%.2d",$i) . ". $show\n";
  $auswahl[$i] = $show;
}
print "\n";
print "$einrueckung(Ende mit anderen Eingabe.)\n";
print "\n";
print "${einrueckung}Auswahl: ";
$input = <>;
chomp($input);
exit if ! defined $auswahl[$input];
print "\n";
print "\n";
print "${einrueckung}Auswahl: $auswahl[$input]\n";
$ENV{PATH} = $ENV{PATH} . ':/usr/sl';
exec("./$auswahl[$input]");
