summaryrefslogtreecommitdiffstats
path: root/.root/etc/profile.d/proxy.sh
blob: 997ea5dc90c457b9c14ae1b18f11fe18d652e779 (plain)
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
# set environmental variables

function proxy-enable() {
	R_="http://127.0.0.1:2080"
	S_="https://127.0.0.1:2080"
	export HTTP_PROXY="${R_}"
	export FTP_PROXY="${R_}"
	export HTTPS_PROXY="${S_}"
	export http_proxy="${R_}"
	export ftp_proxy="${R_}"
	export https_proxy="${S_}"

	# set gsettings
	gsettings set org.gnome.system.proxy mode manual
	for i in http https ftp; do
		gsettings set org.gnome.system.proxy.$i host 127.0.0.1
		gsettings set org.gnome.system.proxy.$i port 2080
	done

	# git
	git config --global http.proxy 127.0.0.1:2080
	git config --global https.proxy 127.0.0.1:2080

	export PROXY_ON_JCG=true
	echo "proxy enabled"
}
alias proxy-on=proxy-enable

function proxy-disable() {
	unset HTTP_PROXY FTP_PROXY HTTPS_PROXY http_proxy ftp_proxy https_proxy
	export -n HTTP_PROXY FTP_PROXY HTTPS_PROXY http_proxy ftp_proxy https_proxy
	gsettings reset org.gnome.system.proxy mode
	git config --global --unset http.proxy
	git config --global --unset https.proxy

	unset PROXY_ON_JCG
	echo "proxy disabled"
}
alias proxy-off=proxy-disable

function proxy-toggle() {
	if [ -z $PROXY_ON_JCG ]; then
		proxy-enable
	else
		proxy-disable
	fi
}