[2657] in BarnOwl Developers
[PATCH] add a random zsig function
daemon@ATHENA.MIT.EDU (Kevin Riggle)
Tue Sep 21 00:01:24 2010
From: Kevin Riggle <kevinr@free-dissociation.com>
To: barnowl-dev@mit.edu
Cc: Kevin Riggle <kevinr@free-dissociation.com>
Date: Tue, 21 Sep 2010 00:01:14 -0400
In-Reply-To: <1285041482-sup-3255@black-opal.free-dissociation.com>
---
perl/lib/BarnOwl.pm | 18 ++++++++++++++++++
variable.c | 3 ++-
2 files changed, 20 insertions(+), 1 deletions(-)
diff --git a/perl/lib/BarnOwl.pm b/perl/lib/BarnOwl.pm
index b097cdd..e08ee50 100644
--- a/perl/lib/BarnOwl.pm
+++ b/perl/lib/BarnOwl.pm
@@ -560,6 +560,24 @@ 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 my $file, '<', $zsigfile or die "File $zsigfile is inaccessible or nonexistent.";
+ my @lines = grep !(/^#/ || /^\s*$/), <$file>;
+ 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..037bb02 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