#!/usr/bin/perl use strict; use warnings; use Cwd qw/ abs_path /; my @dirs = qw( ~/blosxom /srv/relief/blosxom ); s/^~/$ENV{HOME}/ foreach @dirs; # do we want to preserve stamp on this file? sub fits { my $dir = abs_path($_[0]); my $fits = 0; foreach (@dirs) { my $wdir = abs_path($_); $fits++ if $dir =~ m|^$wdir|; } return $fits != 0; } # store original stamps my $original_stamp; foreach (@ARGV) { if ( -f $_ and fits($_) ) { $original_stamp->{$_} = (stat($_))[9]; } } # run vim as you would my $real_vim = `/usr/bin/env -i which vim`; chomp $real_vim; my $cmd = join ' ', $real_vim, @ARGV; system($cmd) == 0 or warn "vim failed: $!"; # restore stamps if they have changed foreach (keys %$original_stamp) { next unless -f $_; my $current_stamp = (stat($_))[9]; unless ($current_stamp == $original_stamp->{$_}) { utime $original_stamp->{$_}, $original_stamp->{$_}, $_; } }