-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzpbash.zp
64 lines (51 loc) · 2.12 KB
/
zpbash.zp
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
(define (bash:command x . args)
"runs a bash command <par>x</par> with the arguments <par>args</par>
and returns its stdout output.
params:
- x: the command to run
- args: the arguments to pass to <par>x</par>
complexity: the complexity of <par>x</par>
returns: the stdout output of <par>x</par>"
(cadr (if (null? args) (system x) (system x (car args)))))
(define bash:ls (curry bash:command "ls"))
(define (bash:pwd)
"runs the bash command pwd and returns its stdout output.
complexity: O(1)
returns: the stdout output of pwd"
(bash:command "pwd"))
(define (bash:uname)
"runs the bash command uname and returns its stdout output.
complexity: O(1)
returns: the stdout output of uname"
(bash:command "uname"))
(define (bash:date)
"runs the bash command date and returns its stdout output.
complexity: O(1)
returns: the stdout output of date"
(bash:command "date"))
(define bash:cd (curry bash:command "cd"))
(define bash:ps (curry bash:command "ps"))
(define bash:rm (curry bash:command "rm"))
(define (bash:unix-timestamp)
"returns the current unix timestamp as a number.
complexity: O(1)
returns: the current unix timestamp"
(string->number (bash:command "date" ["+%s"])))
(define (bash:unix-timestamp-with-nano)
"returns a list constituted of the unix timestamp and current nanoseconds;
only works if the bash date (or gdate) command supports the %N option.
complexity: O(1)
returns: <zepto>[unix-timestamp nanoseconds]</zepto>"
(let* ((stamp (bash:command "date" ["+%s%N"]))
(stampl (- (length stamp) 1))
(divide (- stampl 9)))
(if (char-ci=? (string:ref stamp (- stampl 1)) #\N)
(if (> (length (bash:command "which" ["gdate"])) 2)
(let* ((stamp (bash:command "gdate" ["+%s%N"]))
(stampl (- (length stamp) 1))
(divide (- stampl 9)))
(map string->number (list (substring stamp 0 divide)
(substring stamp divide stampl))))
#f)
(map string->number (list (substring stamp 0 divide)
(substring stamp divide stampl))))))