Browse Source

Added vim-bx, a vim wrapper for bloxsom-like scenarios.

If the edited path matches certain pattern, timestamp is saved and
restored after the edit.
Alois Mahdal 10 years ago
parent
commit
869be33810
1 changed files with 43 additions and 0 deletions
  1. 43
    0
      bin/vim-bx

+ 43
- 0
bin/vim-bx View File

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