source: project/wiki/wmiirc snippets @ 36909

Last change on this file since 36909 was 36909, checked in by sjamaan, 2 years ago

Undo test

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