]> git.cworth.org Git - sup/blob - doc/Hooks.txt
update new user guide for 0.3
[sup] / doc / Hooks.txt
1 Sup's Hook System
2 -----------------
3
4 Sup can be easily customized via its hook system, which allows custom
5 user code to be injected into Sup's execution path by "hooking" the
6 code onto pre-defined events. When those events occur, the code is
7 executed.
8
9 To see which hooks are available, simply run sup -l. Each hook sits in
10 a file in ~/.sup/hooks/. Hooks are written in Ruby, and require no
11 class or method definitions, just the executable code itself.
12
13 Information passes from Sup to the hook code via Ruby variables
14 (actually method calls), and from the hook code back to Sup via a
15 return value. Each hook description lists the variables and return
16 value expected, if any.
17
18 Some example hooks:
19
20 before-poll:
21   ## runs fetchmail before polling
22   if (@last_fetchmail_time || Time.now) < Time.now - 60
23     say "Running fetchmail..."
24     system "fetchmail >& /dev/null"
25     say "Done running fetchmail."
26   end
27   @last_fetchmail_time = Time.now
28
29
30 mime-decode:
31   ## turn text/html attachments into plain text, unless they are part
32   ## of a multipart/alternative pair
33   unless sibling_types.member? "text/plain"
34     case content_type
35     when "text/html"
36       `/usr/bin/w3m -dump -T #{content_type} '#{filename}'`
37     end
38   end