-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfornography-macos.rkt
executable file
·88 lines (73 loc) · 2.82 KB
/
infornography-macos.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env racket
#lang racket/base
(require racket/port racket/system racket/string racket/list)
(define-syntax $
(syntax-rules ()
((_ v)
(getenv (symbol->string (quote v))))))
(define (-> cmd)
(port->string (car (process cmd))))
(define (hostname)
(string-trim (-> "hostname")))
(define (filename->string file)
(call-with-input-file file port->string))
(define (get-match pattern string)
(cadr (regexp-match pattern string)))
(define (cpu)
(string-trim (-> "sysctl -n machdep.cpu.brand_string")))
(define (memory:make-pattern name)
(pregexp (string-append name ":[[:space:]]+([[:digit:]]+)")))
(define (memory:information)
(let* ((mkpattern memory:make-pattern)
(meminfo (-> "vm_stat"))
(total-pages (/ (string->number (string-trim (-> "sysctl -n hw.memsize"))) 4096))
(total (number->string total-pages))
(free (get-match (mkpattern "Pages free") meminfo))
(speculative (get-match (mkpattern "Pages speculative") meminfo)))
(map (λ (num)
(round
(/ (/ (* (string->number num) 4096) 1024) 1024)))
(list total free speculative))))
(define (memory)
(let* ((total (first (memory:information)))
(free (second (memory:information)))
(speculative (third (memory:information)))
(used (- total (+ free speculative))))
(string-join (list (number->string used) "M/"
(number->string total) "M")
"")))
(define (kernel)
(string-trim (-> "uname -s")))
(define (os)
(let* ((os-name (-> "sw_vers -productName"))
(os-version (-> "sw_vers -productVersion")))
(string-join (map string-trim (list os-name os-version)))))
(define data (list "
.......
............... " ($ USER) "@" (hostname) "
.................... Shell: " ($ SHELL) "
......................... Memory: " (memory) "
........................... Kernel: " (kernel) "
............................. OS: " (os) "
............................... Terminal: " ($ TERM) "
..............x................ CPU: " (cpu) "
............xo@................
...........xoo@xxx.............
........o@oxxoo@@@@@@x..xx.....
.....xo@oo...o@@@@@@x...o\\./.
....o@@@@@@@@@@@@@@@@@@@o.\\..
.....x@@@@@@@@@@@o@@@@@@x/.\\.
......@@@@@@@@@@o@@@@@x....
.......@@@@@@@@o@@@@o......
.x@@@@@@@@@@ox.. .....
.@@@@@@@ooooxxxo. ...
...x@@@@@@@@@ooooo@... ..
........@@@@@@@....xoo........
.............@@@....................
........................................
....................x..x................
\n"))
(for-each (λ (s)
(if (string? s)
(display s)
(display "Unknown."))) data)