-
Notifications
You must be signed in to change notification settings - Fork 20
/
proxy.elv
72 lines (58 loc) · 1.35 KB
/
proxy.elv
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# DO NOT EDIT THIS FILE DIRECTLY
# This is a file generated from a literate programing source file located at
# https://github.com/zzamboni/elvish-modules/blob/master/proxy.org.
# You should make any changes there and regenerate it from Emacs org-mode using C-c C-v t
use ./prompt-hooks
use str
var host = ""
var test = $false
var notify = $true
var disable-autoset = $false
var env-vars = [ http_proxy https_proxy ]
fn is-set {
eval "not-eq $E:"(take 1 $env-vars)" ''"
}
fn set-proxy {|@param|
var proxyhost = $host
if (> (count $param) 0) {
set proxyhost = $param[0]
}
if (not-eq $proxyhost "") {
each {|var| set-env $var $host } $env-vars
}
}
fn unset-proxy {
each {|var| unset-env $var } $env-vars
}
fn disable {
set disable-autoset = $true
unset-proxy
}
fn enable {
set disable-autoset = $false
}
fn autoset {|@_|
if (or (not $test) $disable-autoset) {
return
}
if ($test) {
if (and $host (not (eq $host ""))) {
if (and $notify (not (is-set))) {
echo (styled "Setting proxy "$host blue)
}
set-proxy
} else {
fail "You need to set $proxy:host to the proxy to use"
}
} else {
if (and $notify (is-set)) {
echo (styled "Unsetting proxy" blue)
}
unset-proxy
}
}
fn init {
prompt-hooks:add-before-readline $autoset~
prompt-hooks:add-after-readline $autoset~
}
init