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.

39 lines
1.1 KiB

13 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. # I used to think strftime didn't have a non-zero-padded month/day;
  10. # it turns out you can do this with a - after the % (this may not
  11. # work everywhere, so my original workaround is commented below):
  12. my $dayfile = strftime("%Y/%-m/%-e", @t);
  13. # $dayfile =~ s{/[0 ]}{/}gx;
  14. # (Or: Use it anyway and apply an ad-hoc regex fix, because though we often
  15. # feel we know better in this day and age, we are not ashamed of text
  16. # transformation. not when the chips are down. text is the most powerful
  17. # computational abstraction i've ever come close to understanding, if i'm
  18. # honest, and past a certain point life is too short and too precious a span to
  19. # abandon the only tools you have ready to hand.)
  20. my $today = "$root/$dayfile";
  21. if (-d $today) {
  22. print $today;
  23. } else {
  24. my $dirname = $today;
  25. until (-d ($dirname)) {
  26. # If a dir for the month or year doesn't exist, this moves one step up.
  27. # Should land in archives/ if no year.
  28. $dirname = dirname($dirname);
  29. }
  30. print $dirname;
  31. }