Skip to content

Instantly share code, notes, and snippets.

@dr-kd
Created September 6, 2010 13:33
Show Gist options
  • Save dr-kd/567045 to your computer and use it in GitHub Desktop.
Save dr-kd/567045 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use warnings;
use strict;
use Path::Class;
use File::Basename;
use File::Path qw/make_path/;
use String::ShellQuote;
# get the root dir of the repository
my $git_root = `cdup="\$PWD/\$(git rev-parse --show-cdup)" && test -n "\$cdup" && echo \$cdup`;
chomp $git_root;
chdir $git_root;
$git_root = Path::Class::Dir->new($git_root);
my $txt_dir = $git_root->subdir('plaintext');
mkdir $txt_dir unless -e $txt_dir;
my @doc_files_to_commit = `git status`;
chomp $_ for @doc_files_to_commit;
@doc_files_to_commit =
grep { /^#\s+(new|modified).*?doc$/i } @doc_files_to_commit;
for (@doc_files_to_commit) {
$_ =~ s/^.*(?:new|modified)(?: file)?:\s+(.*?)$/$1/;
}
my @extra_commits;
foreach (@doc_files_to_commit) {
my $dir = dirname($_);
my $new_file = basename($_, qw/.doc .DOC/) . ".txt";
push @extra_commits, [Path::Class::File->new($git_root, $_), Path::Class::File->new($txt_dir, $dir, $new_file)];
}
foreach (@extra_commits) {
my ($doc, $txt) = @$_;
my $txt_dir = dirname($txt);
make_path($txt_dir) if !-e $txt_dir;
$doc = shell_quote_best_effort("$doc");
$txt = shell_quote_best_effort("$txt");
my $cmd = "/opt/local/bin/antiword -f $doc > $txt && git add $txt";
system $cmd;
}
@dr-kd
Copy link
Author

dr-kd commented Sep 6, 2010

pre-commit hook for saving msword docs in plain text in a separate branch off git root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment