-
Notifications
You must be signed in to change notification settings - Fork 0
/
.yalrc
47 lines (41 loc) · 1.29 KB
/
.yalrc
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
;; Get our hostname.
;;
;; 1. If /etc/hostname exists, then read that.
;;
;; 2. If "hostname" is a binary on the PATH execute it, and return the output
;;
;; 3. Otherwise give up.
;;
(set! hostname (fn* ()
(cond
(file? "/etc/hostname") (slurp "/etc/hostname")
(file:which "hostname") (car (shell (list (file:which "hostname"))))
true "unknown.host.name")))
;;
;; Trim leading/trailing whichspace from a given string
;;
(set! trim (fn* (str)
"Trim all leading/trailing whitespace from the given string."
(let* (res (match "^[ \t\r\n]*([^ \t\r\n]+)[ \t\r\n]*" str))
(if (list? res)
(car (cdr res))
str))))
;; (print) returns the value it prints, which is annoying in the REPL
;; environment, as you'd see repeated output:
;;
;; > (print 3)
;; 3
;; 3
;; >
;;
;; To avoid this we create a trivial wrapper function that returns nil
;;
(set! puts (fn* (x)
(do
(print x)
nil)))
;;
;; OK now we're done, show a banner and launch the REPL
;;
(print "YAL version %s" (version))
(print "This is ~/.yalrc on %s - %s %s" (trim (hostname)) (os) (arch) )