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
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.
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. The values of variables persists across calls to the
16 same hook, but is NOT available to other hooks. To make the value of a
17 variable available to other hooks, use the get and set methods. Each
18 hook description lists the variables and return value expected, if
21 The following special functions are available to hooks:
23 Displays the string msg to the user at the bottom of the screen.
25 Adds the string msg to the log, which the user can access via the
27 * ask_yes_or_no question
28 Prompts the user with the string question for a yes or no
29 response. Returns true if the user answered yes, false otherwise.
31 Gets the cross-hook value associated with key (which is typically a
32 string). If there is no value for a given key, nil is returned.
34 Sets the cross-hook value associated with key to value. key is
35 typically a string, while value can be whatever type it needs to be,
41 ## runs fetchmail before polling
42 if (@last_fetchmail_time || Time.now) < Time.now - 60
43 say "Running fetchmail..."
44 system "fetchmail >& /dev/null"
45 say "Done running fetchmail."
47 @last_fetchmail_time = Time.now
51 ## turn text/html attachments into plain text, unless they are part
52 ## of a multipart/alternative pair
53 unless sibling_types.member? "text/plain"
56 `/usr/bin/w3m -dump -T #{content_type} '#{filename}'`
61 ## runs a background task
64 set 'bgtask_pid' @bgtask_pid
65 Process.detach(@bgtask_pid) # so we don't have to wait on it when we go to kill it
67 exec "background-task args 2&>1 >> /tmp/logfile"
71 ## kills the background task after the first poll
72 @bgtask_pid = get 'bgtask_pid'
73 Process.kill("TERM", @bgtask_pid) unless @bgtask_pid == nil