3 eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
22 getopts
('n',\
%opt) or pod2usage
(1);
24 @ARGV == 2 or pod2usage
(1);
26 my ($tname,$newfile) = @ARGV;
27 my $tgtpath = dirname
($newfile);
29 my ($sgn_tools_location) = $FindBin::RealBin
=~ m!(^.+/sgn-tools)/!;
30 $sgn_tools_location && -d
$sgn_tools_location
31 or die "could not figure out sgn-tools installed location";
33 my @templatematches = ( glob("~/{T,t}emplates/$tname*"),
34 glob("$sgn_tools_location/development/templates/$tname*"),
35 glob("$FindBin::RealBin/templates/$tname*"),
37 or die "No template found matching '$tname";
39 @templatematches = grep !/~$/,@templatematches; #filter out backup files
41 or die "More than one template matches '$tname':\n",map {" - $_\n"} @templatematches;
43 my ($template) = @templatematches;
45 #add an extension to the target file if it doesn't have one
46 my (undef,undef,$ext) = fileparse
($template,qr/\..+$/);
47 $newfile .= $ext unless $newfile =~ /$ext$/;
51 or mkpath
( $tgtpath, {verbose
=> 1})
52 or die "could not create dir '$tgtpath'";
54 #copy the template file there
55 system( cp
=> -aH
=> $template => $newfile );
56 $CHILD_ERROR and die "Could not copy template from $template to $newfile: $!";
61 if( $template =~ /\.od[pfts]$|\.sx[iwc]$|\.doc$|\.xls$|\.ppt$/ ) {
62 exec 'ooffice', $newfile;
64 #scripts or other things
66 $ENV{EDITOR
} or die "No \$EDITOR environment variable defined, please make sure it's in your .bashrc or similar\n";
74 newtemplate - script to do something
78 newtemplate [options] template_name new_filename
82 -n if passed, do not open $EDITOR after making file
90 Robert Buels, E<lt>rmb32@cornell.eduE<gt>
92 =head1 COPYRIGHT & LICENSE
94 Copyright 2009 Boyce Thompson Institute for Plant Research
96 This program is free software; you can redistribute it and/or modify
97 it under the same terms as Perl itself.