Newer
Older
Francois-Rene Rideau
committed
#+xcvb (module (:depends-on ("pkgdcl")))
(in-package :inferior-shell)
;;--- TODO: move these to FARE-UTILS and/or XCVB-DRIVER ?
(defun make-directory (dir &optional (mode #o755))
;; TODO: move to fare-utils or somewhere else
;; TODO: it's low-level. rename this mkdir or some such, and document use of native-namestring.
#+clozure (ccl::%mkdir dir mode)
Francois-Rene Rideau
committed
#+sbcl (sb-posix:mkdir dir mode)
#-(or clozure sbcl) (NIY 'make-directory))
Francois-Rene Rideau
committed
(defun setenv (var val &optional (overwritep t))
Francois-Rene Rideau
committed
#+sbcl (sb-posix:setenv var val (if overwritep 1 0))
Francois-Rene Rideau
committed
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
(defmacro pipe (values &rest transformers)
(if (null transformers)
values
`(pipe (multiple-value-call ,(car transformers) ,values)
,@(cdr transformers))))
(defun split-lines (x)
(asdf:split-string x :separator #(#\newline)))
(defun split-lines* (x)
(remove-if #'emptyp (split-lines x)))
(defun select-from-hash (keys hash)
(loop :for key :in keys
:collect (gethash key hash)))
(defun do-stream-lines (fun stream)
(loop :for line = (read-line stream nil) :while line
:do (funcall fun line)))
(defun do-string-lines (fun string)
(with-input-from-string (stream string)
(do-stream-lines fun stream)))
(defun println (x)
(princ x) (terpri) (values))
(defun writeln (x &rest keys)
(apply 'write x keys) (terpri) (values))
(defun stripln (x)
(check-type x string)
(let* ((len (length x))
(endlfp (equal (last-char x) #\linefeed))
(endcrlfp (and endlfp (<= 2 len) (eql (char x (- len 2)) #\return)))
(endcrp (equal (last-char x) #\return)))
(cond
((or endlfp endcrp) (subseq x 0 (- len 1)))
(endcrlfp (subseq x 0 (- len 2)))
(t x))))
(defun add-days (year month date days)
(multiple-value-bind (sec min hr d m y dlsp tz)
(decode-universal-time
(+ (encode-universal-time 0 0 0 date month year 0) (* 60 60 24 days)) 0)
(declare (ignore sec min hr dlsp tz))
(values y m d)))
(defun previous-day (year month date)
(add-days year month date -1))
(defun next-day (year month date)
(add-days year month date 1))
`(zsh --nullglob -fc ("print -l " ,(join-strings patterns :separator " "))))
(defun zglob (patterns &key host)
(run/lines `((> 2 "/dev/null") ,@(apply 'zglobcmd (alexandria:ensure-list patterns)))