remove peripheral repositories from get_sgn_repos
[sgn-devtools.git] / new_sgn_file
blobcb5070b0020b46f574ef6872fbd37dbe932df461
1 #!/usr/bin/perl
3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
6 use strict;
7 use warnings;
9 use English;
10 use Carp;
11 use FindBin;
13 use File::Basename;
14 use File::Path;
16 use Getopt::Std;
17 use Pod::Usage;
19 our %opt;
20 getopts('n',\%opt) or pod2usage(1);
22 @ARGV == 2 or pod2usage(1);
24 my ($tname,$newfile) = @ARGV;
25 my $tgtpath = dirname($newfile);
27 my ($sgn_tools_location) = $FindBin::RealBin =~ m!(^.+/sgn-devtools)(/|$)!;
28 $sgn_tools_location && -d $sgn_tools_location
29 or die "could not figure out sgn-devtools installed location";
31 my @templatematches = ( glob("~/{T,t}emplates/$tname*"),
32 glob("$sgn_tools_location/development/templates/$tname*"),
33 glob("$FindBin::RealBin/templates/$tname*"),
35 or die "No template found matching '$tname";
37 @templatematches = grep !/~$/,@templatematches; #filter out backup files
38 @templatematches == 1
39 or die "More than one template matches '$tname':\n",map {" - $_\n"} @templatematches;
41 my ($template) = @templatematches;
43 #add an extension to the target file if it doesn't have one
44 my (undef,undef,$ext) = fileparse($template,qr/\..+$/);
45 $newfile .= $ext unless $newfile =~ /$ext$/;
48 -d $tgtpath
49 or mkpath( $tgtpath, {verbose => 1})
50 or die "could not create dir '$tgtpath'";
52 #copy the template file there
53 system( cp => -aH => $template => $newfile );
54 $CHILD_ERROR and die "Could not copy template from $template to $newfile: $!";
56 exit if $opt{n};
58 #openoffice
59 if( $template =~ /\.od[pfts]$|\.sx[iwc]$|\.doc$|\.xls$|\.ppt$/ ) {
60 exec 'ooffice', $newfile;
62 #scripts or other things
63 else {
64 $ENV{EDITOR} or die "No \$EDITOR environment variable defined, please make sure it's in your .bashrc or similar\n";
65 exec e => $newfile;
68 __END__
70 =head1 NAME
72 new_sgn_file - script to create new SGN files from templates
74 =head1 SYNOPSIS
76 new_sgn_file [options] template_name new_filename
78 Options:
80 -n if passed, do not open $EDITOR after making file
82 =head1 MAINTAINER
84 Robert Buels, Jonathan "Duke" Leto
86 =head1 AUTHOR
88 Robert Buels, E<lt>rmb32@cornell.eduE<gt>
90 =head1 COPYRIGHT & LICENSE
92 Copyright 2009 Boyce Thompson Institute for Plant Research
94 This program is free software; you can redistribute it and/or modify
95 it under the same terms as Perl itself.
97 =cut