-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfornography-freebsd.rkt
executable file
·94 lines (78 loc) · 3.21 KB
/
infornography-freebsd.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
89
90
91
92
93
94
#!/usr/bin/env racket
#lang racket/base
(require racket/math 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 (->number cmd)
(string->number (string-trim (-> cmd))))
(define (hostname)
(string-trim (-> "hostname")))
(define (filename->string file)
(call-with-input-file file port->string))
(define (get-match pattern string)
(cadr (or (regexp-match pattern string) (list "0" "0"))))
(define (cpu)
(string-trim (-> "sysctl -n hw.model")))
(define (memory:round mem-size [chip-guess (- (/ mem-size 8.0) 1.0)] [chip-size 1])
(displayln (list mem-size chip-size chip-guess))
(if (not (zero? (truncate chip-guess)))
(memory:round mem-size (/ chip-guess 2.0) (* chip-size 2))
(* (+ (/ mem-size chip-size) 0.19) chip-size)))
(define (memory:make-pattern name)
(pregexp (string-append name ":[[:space:]]+([[:digit:]]+)")))
(define (memory:information)
(let* ((mkpattern memory:make-pattern)
(pagesize (->number "sysctl -n hw.pagesize"))
(total-pages (memory:round (->number "sysctl -n hw.physmem")))
(total total-pages)
(inactive (* (->number "sysctl -n vm.stats.vm.v_inactive_count") pagesize))
(free (* (->number "sysctl -n vm.stats.vm.v_free_count") pagesize))
(speculative (* (->number "sysctl -n vm.stats.vm.v_cache_count") pagesize)))
(map (λ (num)
(floor num))
(list total free speculative inactive))))
(define (memory)
(let* ((total (first (memory:information)))
(free (second (memory:information)))
(speculative (third (memory:information)))
(inactive (fourth (memory:information)))
(used (- total (+ free speculative inactive))))
(string-join (list (number->string (inexact->exact (floor (/ used (* 1024 1024))))) "M/"
(number->string (inexact->exact (floor (/ total (* 1024 1024))))) "M")
"")))
(define (os)
(string-trim (-> "uname -s")))
(displayln (memory))
(define data (list "
.......
............... " ($ USER) "@" (hostname) "
.................... Shell: " ($ SHELL) "
......................... Memory: " (memory) "
........................... OS: " (os) "
............................. Terminal: " ($ TERM) "
............................... CPU: " (cpu) "
..............x................
............xo@................
...........xoo@xxx.............
........o@oxxoo@@@@@@x..xx.....
[email protected]@@@@@@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)