source: examples/owlconf.erik @ 8ee73f8d

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8ee73f8d was 8ee73f8d, checked in by Erik Nygren <nygren@mit.edu>, 19 years ago
Fixed a memory reference bug in delete and undelete commands. Added support for perl to call directly back into owl. Changed the implementation of owl::command("...") to immediately call back into owl. This allows perl to get the return value of strings returned by owl commands. Added the getview command which returns the name of the current view's filter. Added the getvar command which returns the value of a variable. Added an example to examples/owlconf.erik which uses TAB to narrow and restore the view. Added an example to examples/owlconf.erik which uses M-c to color messages matching the current one green.
  • Property mode set to 100644
File size: 7.5 KB
Line 
1### The owlconf config file   -*- perl -*- 
2###  $Id$
3
4### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
5### This is an example file intended to demonstrate how to use
6### various features of owl.  Some of the key bindings, in particular,
7### are more for examples than things you may actually want to use.
8### Make sure to read through it first and understand it before just using it.
9### Don't blame me if anything in here ends up vaporizing your dog.
10### !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!! !!!!!WARNING!!!!!
11
12###
13### This file is interpreted by the perl interpreter.
14### If you wish to execute an owl command use the
15### function owl::command().  i.e.
16###
17###      owl::command("set zsigproc /mit/kretch/bin/getzsig");
18###
19### will set the owl variable zsigproc.  Subroutines created with
20### the names below will be executed at the specified times:
21###
22###     subroutine name    properties
23###     ---------------    ----------
24###     owl::startup()     run when owl first starts
25###     owl::shutdown()    run when owl exits
26###     owl::format_msg()  run when a new message arrives, the return
27###                           value is used to display the message on the
28###                           screen
29###     owl::receive_msg() run when a message is received, and after
30###                        it has been added to the message list
31###
32###
33### The following variables will be set each time a message is recevied:
34###
35###     $owl::class, $owl::instance, $owl::recipient,
36###     $owl::sender, $owl::opcode, $owl::zsig,
37###     $owl::msg, $owl::time, $owl::host, @owl::fields, $owl::id
38###   
39
40# tokens for sepbar are:
41#    .username = ping
42#    >username = login
43#    <username = logout
44#    :username = personal message
45#    M         = mail received
46my @sepbartokens = ();
47
48
49# adds a sepbartoken and also updates the appendtosepbar variable
50sub sepbartokens_add {
51    my ($token) = @_;
52    $token =~ s/"//g;  # "
53    unshift @sepbartokens, $token;
54    pop @sepbartokens if (@sepbartokens > 80);
55    sepbartokens_set();
56}
57
58# trims a sepbartoken from the list also updates the appendtosepbar variable
59sub sepbartokens_trim {
60    my ($token) = @_;
61    @sepbartokens = map { if ($_ ne $token) { $_; } else { (); } } @sepbartokens;
62    sepbartokens_set();
63}
64
65# trims a sepbartoken from the list also updates the appendtosepbar variable
66sub sepbartokens_set {
67    owl::command(sprintf "set -q appendtosepbar \"%s\"", (join " ", @sepbartokens));
68}
69
70my $restoreview = undef;
71sub swapview {
72    my $curview = owl::command("getview");
73    if ($restoreview) {
74        owl::command("view $restoreview");
75        $restoreview = undef;
76    } else {
77        $restoreview = $curview;
78        owl::command("smartnarrow");
79    }
80}
81
82my $lastcolored = undef;
83sub colorthread {
84    if ($lastcolored) {
85        owl::command("filter $lastcolored -c default");
86    }
87    my $smartfilt = owl::command("smartfilter");
88    if (!$smartfilt or $smartfilt eq $lastcolored) {
89        owl::command("filter $lastcolored -c default");
90        $lastcolored = undef;
91    } else {
92        owl::command("filter $smartfilt -c green");
93        $lastcolored = $smartfilt;
94    }
95}
96
97sub owl::startup {
98    owl::command("set -q logging off");
99    owl::command("set -q zsigproc /home/nygren/bin/owlzsigs");
100    owl::command("set -q startuplogin off");
101    owl::command("set -q shutdownlogout off");
102    #owl::command("set personalbell on");
103    owl::command("set -q rxping on");
104    owl::command("set -q typewinsize 5");
105    if ($ENV{"DISPLAY"} eq ":0") {
106      owl::command("set -q webbrowser galeon"); 
107    }
108    owl::command("filter me recipient ".$ENV{"USER"});
109    owl::command("filter help class help");
110    owl::command("filter quiet not ( class ^greed|geek|help|login$ or instance white-magic )");   
111
112    owl::command("alias z zwrite");
113    owl::command("alias zc zwrite -c");
114
115    # Send zephyrs with "C-c C-c". 
116    # Note that this will cause "C-c" to not work...
117    owl::command("bindkey editmulti \"C-c C-c\" command editmulti:done");
118
119    # Make "d" ignore current movement direction
120    owl::command("bindkey recv d command ( delete --no-move ; next --skip-deleted )");
121
122    # Useful keys for reading and deleting by class/instance
123    owl::command("bindkey recv M-k command ( smartnarrow ; delete view )");
124    owl::command("bindkey recv M-l command ( expunge ; view all )");
125    owl::command("bindkey recv M-K command ( smartnarrow ; delete view ; expunge ; view all )");
126
127    # toggle between a view and a smartnarrow with TAB
128    owl::command("alias swapview perl swapview();");
129    owl::command("bindkey recv C-i command swapview");
130
131    # color the current thread
132    owl::command("alias colorthread perl colorthread();");
133    owl::command("bindkey recv M-c command colorthread");
134
135    # Make 'M-s' insert a <scritchscritchscritch> sequence with a random
136    # number of scritches.
137    owl::command(q(bindkey edit M-s command perl owl::command("edit:insert-text <".("scritch"x int(1+rand(5))).">")));
138
139}
140
141sub owl::shutdown {
142#    not doing anything at the moment...
143}
144
145# run to format a message
146sub owl::format_msg {
147    my $out, $tmp;
148
149    $owl::sender=~s/\@ATHENA\.MIT\.EDU$//;
150    $owl::sender=~s/\@local-realm$//;
151
152    if (uc($owl::opcode) eq "PING") {
153        return("\@bold(PING) from \@bold($owl::sender)\n");
154    } elsif (uc($owl::class) eq "LOGIN") {
155        if (uc($owl::opcode) eq "USER_LOGIN") {
156            $out="\@bold(LOGIN)";
157        } elsif (uc($owl::opcode) eq "USER_LOGOUT") {
158            $out="\@bold(LOGOUT)";
159        } else {
160            $out="\@bold(UNKNOWN)";
161        }
162        $out.=" for \@bold($owl::sender) at $fields[0] on $fields[2]\n";
163        return($out);
164    } elsif (uc($owl::class) eq "MAIL" and uc($owl::instance) eq "INBOX") {
165        $out = "\@bold(MAIL) ";
166        if ($owl::msg =~ /^From:\s+(.+)\s*$/m) { $out .= "From $1 "; }
167        if ($owl::msg =~ /^To:\s+(.+)\s*$/m) { $out .= "To $1 "; }
168        if ($owl::msg =~ /^Subject:\s+(.+)\s*$/m) { $out .= "Subject $1 "; }
169        return($out."\n");
170    }
171
172    $out = sprintf "[mit,%s,%s] / %s / %s", lc($owl::class), 
173                   lc($owl::instance), $owl::time, lc($owl::host);
174    if ($owl::opcode ne "") {$out.=" op:$owl::opcode";}
175    $out.="\n";
176    $out.= "  \@bold($owl::sender)> ";
177    if ($owl::zsig ne "") {
178        my $zsig = $owl::zsig;
179        $zsig =~ s/(\n.*)+$/ [...]/;
180        if (length($zsig)+5+length($owl::sender) > 70) {
181            $out.="# ...";
182        } else {
183            $out.="# $zsig";
184        }
185    }
186    $out.="\n";         
187
188    # indent it
189    $tmp=$owl::msg;
190    $tmp=~s/^/    /g;
191    $tmp=~s/\n/\n    /g;
192    $out.=$tmp;
193
194    # make personal messages bold
195    if (uc($owl::class) eq "MESSAGE" &&
196        uc($owl::instance) eq "PERSONAL") {
197        $out="\@bold{".$out."}";
198    }
199
200    return($out."\n");
201}
202
203# run when a message is received, and after
204# it has been added to the message list.
205sub owl::receive_msg() {
206    my $out, $tmp;
207
208    $owl::sender=~s/\@ATHENA\.MIT\.EDU$//;
209    $owl::sender=~s/\@local-realm$//;
210
211    if (uc($owl::opcode) eq "PING") {
212        sepbartokens_add(".$owl::sender");
213        owl::command("delete -id $owl::id");
214    } elsif (uc($owl::class) eq "LOGIN") {
215        owl::command("delete -id $owl::id");
216        if (uc($owl::opcode) eq "USER_LOGIN") {
217            sepbartokens_add(">$owl::sender");
218            sepbartokens_trim("<$owl::sender");
219        } elsif (uc($owl::opcode) eq "USER_LOGOUT") {
220            sepbartokens_add("<$owl::sender");
221            sepbartokens_trim(">$owl::sender");
222        } 
223    } elsif (uc($owl::class) eq "MAIL") {
224        owl::command("delete -id $owl::id");
225        sepbartokens_add("M");
226    }
227
228
229    # make personal messages bold
230    if (uc($owl::class) eq "MESSAGE" &&
231        uc($owl::instance) eq "PERSONAL") {
232        sepbartokens_trim(".$owl::sender");
233        sepbartokens_add(":$owl::sender");
234    }
235
236    return 1;
237}
Note: See TracBrowser for help on using the repository browser.