diff --git a/.local/share/common-lisp/source/ambrevar/shell.lisp b/.local/share/common-lisp/source/ambrevar/shell.lisp index 32906c64..df1ea0d7 100644 --- a/.local/share/common-lisp/source/ambrevar/shell.lisp +++ b/.local/share/common-lisp/source/ambrevar/shell.lisp @@ -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)