scheme shell

Import Env Into Shell In Mac Os

 #! /usr/local/bin/scsh \
 -e main -s

file name: write-setenvs.scm

In Mac OS X, personal environment variable settings go in ~/.MacOSX/environment.plist, a property list file in XML-format. These settings affect the environment of applications, including the, but not the shell per se. However, they can be imported explicitly in the tcsh init file by

eval `write-setenvs.scm`

(if the script resides in the exe search path). Useful for remote logins.

Related Links

Setting ennvironment variables for user processes

Environment variables

macosxhints -- Populate tcsh environment variables via a script

Da Code

uses the defaults(1) utility to access the plist. The output of "defaults read $HOME/.MacOSX/environment" looks like so: { CC = "gcc-3.3"; CPP = "cpp-3.3"; "SCSH_LIB_DIRS" = "#f \\"/Users/Shared/Eunuchs/lib/scsh-libs\\""; } The output format doesn't seem to be specified, though.

Works with scsh-0.6.6 for the tcsh in OS X 1.3; easily adapted to the bash. !#

(define assignment-re (rx (* whitespace) (| (submatch (+ alphanumeric)) (: #\" (submatch (+ (| alphanumeric #\_))) #\")) " = " (: #\" (submatch (* any)) "\"; ")))

;; returns a string alist as used by the Scsh's env procedures (define (defaults->alist inport) (awk (read-line inport) (line) ((bindings '())) (,@assignment-re => (lambda (match) (cons (cons (or (match:substring match 1) (match:substring match 2)) (match:substring match 3)) bindings)))))

(define (write-csh-assignment var:val) (format #t "setenv ~a '~a';~%" (car var:val) (cdr var:val)))

(define (main args) (for-each write-csh-assignment (defaults->alist (run/port (defaults read ,(home-file ".MacOSX/environment")))) ))

ImportEnvIntoShellInMacOs - raw wiki source | code snippets archive