-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-proxies.el
35 lines (30 loc) · 1.41 KB
/
init-proxies.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
;;----------------------------------------------------------------------------
;; Pick up http_proxy & https_proxy from Mac system config using proxy-config
;; tool available from
;; http://www.cs.usyd.edu.au/~massad/project-proxy-config.html
;;----------------------------------------------------------------------------
(when (and *is-a-mac* (executable-find "proxy-config"))
(defun mac-configured-proxy (proto)
(string-rtrim (shell-command-to-string
(concat "proxy-config " (cdr (assoc-string proto '(("http" . "-h") ("https" . "-s"))))))))
(defun extract-host-and-port (url-string)
(if (string-match "^[a-z]+://\\([^/]+\\)" url-string)
(match-string 1 url-string)
url-string))
(defun assq-delete-all-with-test (k l &optional test)
(let ((test-func (or test #'eq)))
(loop for entry in l
unless (funcall test-func k (car entry))
collect entry)))
(defun mac-set-proxy-vars ()
(interactive)
(require 'url)
(loop for proto in '("http" "https")
for proxy = (mac-configured-proxy proto)
do
(setenv (concat proto "_proxy" proxy))
(setq url-proxy-services
(append (assq-delete-all-with-test proto url-proxy-services #'equal)
(if (not (equal "" proxy)) (list (cons proto (extract-host-and-port proxy)))))))
(message "proxy variables updated")))
(provide 'init-proxies)