From: Don Armstrong <don@donarmstrong.com>
Date: Fri, 8 Feb 2008 05:56:37 +0000 (+0000)
Subject:  * Add makefile and stuff to start using fortune where possible
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2815d7ed754a1632c7fb1e5e4f18557661ee7fc7;p=lib.git

 * Add makefile and stuff to start using fortune where possible
---

diff --git a/signature_stuff/Makefile b/signature_stuff/Makefile
new file mode 100644
index 0000000..bef1532
--- /dev/null
+++ b/signature_stuff/Makefile
@@ -0,0 +1,7 @@
+
+all: $(patsubst %.txt,%.txt.dat,$(wildcard *.txt))
+
+%.txt.dat: %.txt
+	strfile $< $@
+
+.PHONY: all
\ No newline at end of file
diff --git a/signature_stuff/pick_a_quote.pl b/signature_stuff/pick_a_quote.pl
index a2de709..83f319a 100755
--- a/signature_stuff/pick_a_quote.pl
+++ b/signature_stuff/pick_a_quote.pl
@@ -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
index 0000000..11fbea4
--- /dev/null
+++ b/signature_stuff/quote_misc.txt
@@ -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]