source: project/wiki/wmiirc snippets @ 36908

Last change on this file since 36908 was 36908, checked in by sjamaan, 20 months ago


File size: 2.5 KB
2== wmiirc snippets
4Post your favorite wmiirc scriptlets here.
6=== Tag cycling
8Normally you have numbered tags and pressing Mod+n gives you tag n, but
9some people prefer to have more meaningful tag names.  This means more
10work to type them in, so here's a way to navigate to the left or to
11the right of the current tab through the tabs as they appear in the bar.
13<enscript highlight=scheme>
14   ((key ,modkey "comma")
15    . ,(lambda _
16         (let loop ((list (wmii:tags))
17                    (tag (wmii:tag)))
18           (cond
19            ((or (null? list) (null? (cdr list))) #f)
20            ((string=? (cadr list) tag) (wmii:goto-tag (car list)))
21            (else (loop (cdr list) tag))))))
22   ((key ,modkey "period")
23    . ,(lambda _
24         (and-let* ((tag (member (wmii:tag) (wmii:tags)))
25                    ((not (null? (cdr tag)))))
26           (wmii:goto-tag (cadr tag)))))
29=== Battery charge in status bar on NetBSD
31On my notebook, I want to have a quick view on my battery charge at
32all times.  Starting with NetBSD 5.0, you can use the program
33"envstat" to obtain battery info (before you'd use "apm").
34Unfortunately, there's no easy way to parse its output in a script.
35You could use the XML output, but then you'd have to wade through the
36entire output because the {{-s}} switch does not restrict the proplib
37output to the given sensors.
39On my iBook G4 laptop, the battery is called {{smartbat0}}.
41<enscript highlight=scheme>
42(define (get-charge)
43  ;; Note that ordering of -s args doesn't influence ordering of output!
44  (let* ((lines (cddr (with-input-from-pipe "envstat -s 'smartbat0:Battery design cap,smartbat0:Battery charge'" read-lines)))
45         (max (string->number
46               (irregex-match-substring (irregex-search 'real (car lines)) 0)))
47         (charge (string->number
48                  (irregex-match-substring (irregex-search 'real (cadr lines)) 0))))
49    (/ (round (/ (* charge 1000) max)) 10)))
52This procedure gives the output at a granularity of one tenth percent.
53I check the output in my status procedure that is run once every
54second and display a warning if the charge drops below a threshold:
56<enscript highlight=scheme>
57(let ((warned? #f))
58  (let loop ()
59    (let ((charge (get-charge)))
60      (wmii:write-tab
61       "rbar" "status"
62       (conc charge "% | " (seconds->string (current-seconds))))
63      (when (and (<= charge 5) (not warned?))
64        (set! warned? #t)
65        (process-run "xmessage -center 'Low battery power!'"))
66      (when (and warned? (> charge 5))
67        (set! warned #f)))
68    (thread-sleep! 1)
69    (loop)))
Note: See TracBrowser for help on using the repository browser.