ambrevar/shell: Extend `env'.
parent
a8b9fa81f2
commit
6e957d1819
|
@ -15,11 +15,20 @@
|
|||
(local-time:format-rfc1123-timestring nil (local-time:now)))
|
||||
|
||||
(export-always 'env)
|
||||
(defun env ()
|
||||
"Return the environment variables as an alist."
|
||||
(mapcar (lambda (line)
|
||||
(str:split "=" line :limit 2))
|
||||
(str:split (string #\newline) (cmd:$cmd "env"))))
|
||||
(defun env (&optional key)
|
||||
"Return the environment variables as a proper alist.
|
||||
With KEY, return the corresponding environment variable value, and the whole
|
||||
list as a second value."
|
||||
(let ((result
|
||||
(mapcar (lambda (line)
|
||||
(let ((key-value (str:split "=" line :limit 2)))
|
||||
(cons (first key-value)
|
||||
(str:split (uiop:inter-directory-separator)
|
||||
(second key-value)))))
|
||||
(str:split (string #\newline) (cmd:$cmd "env")))))
|
||||
(if key
|
||||
(alex:assoc-value result key :test #'string=)
|
||||
result)))
|
||||
|
||||
(export-always 'file->string)
|
||||
(defun file->string (path)
|
||||
|
|
Loading…
Reference in New Issue