#! /opt/local/bin/scsh -s !# ;; Quick utility to extract the HTTP proxy information from 'scutil --proxy' (define handle-proxy-details (let ((proxy-rx (rx (: "HTTPProxy" (* space) #\: (* space) (submatch (+ any))))) (port-rx (rx (: "HTTPPort" (* space) #\: (* space) (submatch (+ digit))))) (exception-rx (rx (: (+ digit) (* space) #\: (* space) (submatch (+ any)))))) (lambda (line host port exceptions) (cond ((regexp-search proxy-rx line) => (lambda (m) (values (match:substring m 1) port exceptions))) ((regexp-search port-rx line) => (lambda (m) (values host (match:substring m 1) exceptions))) ((regexp-search exception-rx line) => (lambda (m) (values host port (cons (match:substring m 1) exceptions)))) (else (values host port exceptions)))))) (call-with-values (lambda () (port-fold (run/port (scutil --proxy)) read-line handle-proxy-details #f #f '())) (lambda (host port exceptions) (if host (let ((proxy (format #f "http://~a:~a/" host (or port 80)))) (format #t "echo 'proxying via ~a'; export http_proxy='~a'~%" proxy proxy)) (format #t "echo 'no proxy'; unset http_proxy~%")) (if (null? exceptions) (format #t "unset no_proxy~%") (format #t "export no_proxy='~a'~%" (let loop ((l exceptions) (res "")) (if (null? l) res (loop (cdr l) (format #f "~a~a~a" res (if (= (string-length res) 0) "" ",") (car l)))))))))