]> git.donarmstrong.com Git - lib.git/commitdiff
* Add makefile and stuff to start using fortune where possible
authorDon Armstrong <don@donarmstrong.com>
Fri, 8 Feb 2008 05:56:37 +0000 (05:56 +0000)
committerDon Armstrong <don@donarmstrong.com>
Fri, 8 Feb 2008 05:56:37 +0000 (05:56 +0000)
signature_stuff/Makefile [new file with mode: 0644]
signature_stuff/pick_a_quote.pl
signature_stuff/quote_misc.txt [new file with mode: 0644]

diff --git a/signature_stuff/Makefile b/signature_stuff/Makefile
new file mode 100644 (file)
index 0000000..bef1532
--- /dev/null
@@ -0,0 +1,7 @@
+
+all: $(patsubst %.txt,%.txt.dat,$(wildcard *.txt))
+
+%.txt.dat: %.txt
+       strfile $< $@
+
+.PHONY: all
\ No newline at end of file
index a2de7091fbd97283b582a21154ff6a34b48a18b7..83f319ad6cef1a9ab0b4b6f0cb83450c23384a37 100755 (executable)
@@ -13,28 +13,31 @@ $quote_file ||= User->Home."/lib/signature_stuff/quote.txt";
 
 my $sigfile      = new IO::File User->Home."/.signature", 'w' or die "Unable to open ~/.signature for writing; $!";
 my $templatefile = new IO::File $temp_file, 'r' or die "Unable to open $temp_file $!";
-my $quotesfile   = new IO::File $quote_file,'r' or die "Unable to open $quote_file $!";
 
-my $template = '';
-
-while (<$templatefile>) {
-     $template.=$_;
-}
+local $/;
+my $template =<$templatefile>;
 
 undef $templatefile;
 
-my $quotes = '';
-
-while (<$quotesfile>) {
-     $quotes.=$_;
+my $quote;
+my $fortune;
+if (-e $quote_file.'.dat' and open($fortune,'-|','fortune',$quote_file)) {
+     local $/;
+     $quote = <$fortune>;
+     close($fortune);
+     $quote =~ s/\n$//;
+}
+else {
+     my $quotes = '';
+     my $quotesfile   = new IO::File $quote_file,'r' or die "Unable to open $quote_file $!";
+     local $/;
+     $quotes = <$quotesfile>;
+     undef $quotesfile;
+     my @quotes = split /\n*\%\n*/s, $quotes;
+     undef $quotes;
+     my $quote = $quotes[rand(@quotes)];
 }
 
-undef $quotesfile;
-
-my @quotes = split /\n*\%\n*/s, $quotes;
-undef $quotes;
-
-my $quote = $quotes[rand($#quotes+1)];
 
 $template =~ s/\[\%\s*quote\s*\%\]/$quote/;
 
diff --git a/signature_stuff/quote_misc.txt b/signature_stuff/quote_misc.txt
new file mode 100644 (file)
index 0000000..11fbea4
--- /dev/null
@@ -0,0 +1,4 @@
+With that he haled me before the wali and I statsed an artistic meal
+of stick, till I fell in a faint.
+ -- The Thousand Nights And One Night (The Tale of Ghānim Ibn Ayyūr)
+    [v1 p324]