12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Cwd qw/ abs_path /;
  5. my @dirs = qw( ~/blosxom /srv/relief/blosxom );
  6. s/^~/$ENV{HOME}/ foreach @dirs;
  7. # do we want to preserve stamp on this file?
  8. sub fits {
  9. my $dir = abs_path($_[0]);
  10. my $fits = 0;
  11. foreach (@dirs) {
  12. my $wdir = abs_path($_);
  13. $fits++ if $dir =~ m|^$wdir|;
  14. }
  15. return $fits != 0;
  16. }
  17. # store original stamps
  18. my $original_stamp;
  19. foreach (@ARGV) {
  20. if ( -f $_ and fits($_) ) {
  21. $original_stamp->{$_} = (stat($_))[9];
  22. }
  23. }
  24. # run vim as you would
  25. my $real_vim = `/usr/bin/env -i which vim`;
  26. chomp $real_vim;
  27. my $cmd = join ' ', $real_vim, map { "\"$_\"" } @ARGV;
  28. system($cmd) == 0
  29. or warn "vim failed: $!";
  30. # restore stamps if they have changed
  31. foreach (keys %$original_stamp) {
  32. next unless -f $_;
  33. my $current_stamp = (stat($_))[9];
  34. unless ($current_stamp == $original_stamp->{$_}) {
  35. utime $original_stamp->{$_}, $original_stamp->{$_}, $_;
  36. }
  37. }