[2651] in BarnOwl Developers
[PATCH] add a random zsig function
daemon@ATHENA.MIT.EDU (Kevin Riggle)
Sun Sep 19 02:43:23 2010
From: Kevin Riggle <kevinr@free-dissociation.com>
To: barnowl-dev@mit.edu
Cc: Kevin Riggle <kevinr@free-dissociation.com>
Date: Sun, 19 Sep 2010 02:43:11 -0400
In-Reply-To: <1284872413-sup-4011@black-opal.free-dissociation.com>
---
perl/lib/BarnOwl.pm | 20 ++++++++++++++++++++
variable.c | 3 ++-
2 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/perl/lib/BarnOwl.pm b/perl/lib/BarnOwl.pm
index b097cdd..db4f665 100644
--- a/perl/lib/BarnOwl.pm
+++ b/perl/lib/BarnOwl.pm
@@ -560,6 +560,26 @@ sub default_zephyr_signature
return $zsig;
}
+=head3 random_zephyr_signature
+
+Retrieve a random line from ~/.zsigs (except those beginning with '#')
+and use it as the zephyr signature.
+
+=cut
+
+sub random_zephyr_signature
+{
+ my $zsigfile = "$ENV{'HOME'}/.zsigs";
+ open FILE, $zsigfile or die "No zsigfile $zsigfile";
+ while (<FILE>) {
+ push @lines, $_ unless /^#/ || /^\s*$/;
+ }
+ close FILE;
+ my $zsig = $lines[int(rand(scalar @lines))];
+ chomp $zsig;
+ return $zsig;
+}
+
# Stub for owl::startup / BarnOwl::startup, so it isn't bound to the
# startup command. This may be redefined in a user's configfile.
sub startup
diff --git a/variable.c b/variable.c
index 1175ede..6bea7e8 100644
--- a/variable.c
+++ b/variable.c
@@ -212,7 +212,8 @@ static owl_variable variables_to_init[] = {
"zsig perl function",
"Called every time you start a zephyrgram without an\n"
"explicit zsig. The default setting implements the policy\n"
- "described in the documentation for the 'zsig' variable.\n"),
+ "described in the documentation for the 'zsig' variable.\n"
+ "See also BarnOwl::random_zephyr_signature().\n"),
OWLVAR_STRING( "zsig" /* %OwlVarStub */, "",
"zephyr signature",
--
1.7.1