org-file-index 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use POSIX qw/strftime/;
  5. my $outputfile = "/home/swflint/org/index.org";
  6. my $date = strftime "<%Y-%m-%d %a %H:%M>", localtime;
  7. my $fileHeader = <<EOF;
  8. #+Title: Org File Index
  9. #+AUTHOR: Sam Flint
  10. #+EMAIL: swflint\@flintfam.org
  11. #+DATE: $date
  12. #+INFOJS_OPT: view:info toc:nil path:http://flintfam.org/org-info.js
  13. #+OPTIONS: toc:nil H:5 ':t *:t d:nil stat:nil todo:nil
  14. #+LATEX_CLASS_OPTIONS: [10pt,twocolumn]
  15. #+LATEX_HEADER: \\usepackage[landscape,margin=0.125 in]{geometry}
  16. #+LATEX_HEADER: \\pagestyle{empty}
  17. * Org
  18. EOF
  19. open(my $output, ">", $outputfile) or die "Unable to open \"$outputfile\" the output file, $!";
  20. print $output $fileHeader;
  21. opendir(my $directory, "/home/swflint/org/")
  22. or die "Can't open the directory: $!";
  23. my @directories;
  24. while (my $file = readdir $directory) {
  25. if ($file =~ m/^\..*/) {
  26. next;
  27. } elsif (-d "/home/swflint/org/$file") {
  28. push @directories, $file;
  29. } elsif ($file =~ m/.*\.org$/) {
  30. (my $linkName = $file) =~ s/\.[^.]+$//;
  31. $linkName =~ s/-/ /g;
  32. $linkName =~ s/\b(\w)/\U$1/g;
  33. print $output " - [[file:~/org/$file][$linkName]]\n"
  34. } else {
  35. next;
  36. }
  37. }
  38. closedir $directory;
  39. foreach (sort @directories) {
  40. my $newDir = $_;
  41. if ($newDir =~ "auto" or $newDir =~ "data") {
  42. next;
  43. }
  44. opendir(my $theDirectory, "/home/swflint/org/$newDir/")
  45. or die "Can't open directory: $!";
  46. my $fancyDir = $newDir;
  47. $fancyDir =~ s/-/ /g;
  48. $fancyDir =~ s/\b(\w)/\U$1/g;
  49. print $output "\n** Org: $fancyDir\n\n";
  50. print $output " - [[file:~/org/$newDir/][$fancyDir]]\n";
  51. while (my $file = readdir $theDirectory) {
  52. if ($file =~ m/^\..*/
  53. or -d "/home/swflint/org/$newDir/$file") {
  54. next;
  55. } elsif ($file =~ m/.*\.org$/) {
  56. (my $linkName = $file) =~ s/\.[^.]+$//;
  57. $linkName =~ s/-/ /g;
  58. $linkName =~ s/\b(\w)/\U$1/g;
  59. print $output " - [[file:~/org/$newDir/$file][$linkName]]\n";
  60. } else {
  61. next;
  62. }
  63. }
  64. }
  65. close $output;