]> git.donarmstrong.com Git - lib.git/blob - signature_stuff/pick_a_quote.pl
fix missing ) for org-mode
[lib.git] / signature_stuff / pick_a_quote.pl
1 #! /usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 use IO::File;
7
8 use User;
9
10 my ($temp_file,$quote_file) = @ARGV;
11 $temp_file  ||= User->Home."/lib/signature_stuff/sigtemplate.txt";
12 $quote_file ||= User->Home."/lib/signature_stuff/quote.txt";
13
14 # my $sigfile      = new IO::File User->Home."/.signature", 'w' or die "Unable to open ~/.signature for writing; $!";
15 my $templatefile = new IO::File $temp_file, 'r' or die "Unable to open $temp_file $!";
16
17 local $/;
18 my $template =<$templatefile>;
19
20 undef $templatefile;
21
22 my $quote;
23 my $fortune;
24 if (-e $quote_file.'.dat' and open($fortune,'-|','fortune',$quote_file)) {
25      local $/;
26      $quote = <$fortune>;
27      close($fortune);
28      $quote =~ s/\n$//;
29 }
30 else {
31      my $quotes = '';
32      my $quotesfile   = new IO::File $quote_file,'r' or die "Unable to open $quote_file $!";
33      local $/;
34      $quotes = <$quotesfile>;
35      undef $quotesfile;
36      my @quotes = split /\n*\%\n*/s, $quotes;
37      undef $quotes;
38      my $quote = $quotes[rand(@quotes)];
39 }
40
41
42 $template =~ s/\[\%\s*quote\s*\%\]/$quote/;
43
44 print $template;