Dotfiles, utilities, and other apparatus.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1018 B

13 years ago
12 years ago
13 years ago
13 years ago
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use 5.10.0;
  5. use POSIX qw(strftime);
  6. use File::Basename;
  7. my $root = $ENV{HOME} . '/p1k3/archives';
  8. my @t = localtime;
  9. # strftime doesn't have a non-zero-padded month/day?
  10. my $dayfile = strftime("%Y/%m/%e", @t);
  11. $dayfile =~ s{/[0 ]}{/}gx;
  12. # (Or: Use it anyway and apply an ad-hoc regex fix, because though we often
  13. # feel we know better in this day and age, we are not ashamed of text
  14. # transformation. not when the chips are down. text is the most powerful
  15. # computational abstraction i've ever come close to understanding, if i'm
  16. # honest, and past a certain point life is too short and too precious a span to
  17. # abandon the only tools you have ready to hand.)
  18. my $today = "$root/$dayfile";
  19. if (-d $today) {
  20. print $today;
  21. } else {
  22. my $dirname = $today;
  23. until (-d ($dirname)) {
  24. # If a dir for the month or year doesn't exist, this moves one step up.
  25. # Should land in archives/ if no year.
  26. $dirname = dirname($dirname);
  27. }
  28. print $dirname;
  29. }