349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
-
-
+
+
+
-
+
-
-
+
+
+
-
+
|
(caar uname-res))))
(define (save-environment-as-files fname #!key (ignorevars (list "USER" "HOME" "DISPLAY" "LS_COLORS" "XKEYSYMDB" "EDITOR")))
(let ((envvars (get-environment-variables))
(whitesp (regexp "[^a-zA-Z0-9_\\-:;,.\\/%$]")))
(with-output-to-file (conc fname ".csh")
(lambda ()
(for-each (lambda (key)
(let* ((val (cdr key))
(for-each (lambda (keyval)
(let* ((key (car keyval))
(val (cdr keyval))
(sval (if (string-search whitesp val)(conc "\"" val "\"") val)))
(print (if (member key ignorevars)
"# setenv "
"setenv ")
(car key) " " sval)))
key " " sval)))
envvars)))
(with-output-to-file (conc fname ".sh")
(lambda ()
(for-each (lambda (key)
(let* ((val (cdr key))
(for-each (lambda (keyval)
(let* ((key (car keyval))
(val (cdr keyval))
(sval (if (string-search whitesp val)(conc "\"" val "\"") val)))
(print (if (member key ignorevars)
"# export "
"export ")
(car key) "=" sval)))
key "=" sval)))
envvars)))))
;; set some env vars from an alist, return an alist with original values
;; (("VAR" "value") ...)
(define (alist->env-vars lst)
(if (list? lst)
(let ((res '()))
|