Files

57 lines
1.4 KiB
Fish

function __proxy_enable
set IP 127.0.0.1
set PORT 7890
set PROTO socks5
set OPT -g -x
for arg in $argv
switch $arg
case "-non-global"
set OPT -x
case "-socks" "-socks5"
set PROTO socks5
case "-socks5h"
set PROTO socks5h
case "-http"
set PROTO http
case '*'
if test (string sub -l 1 -- "$arg") != "-"
if string match -qr '^[0-9]+$' -- "$arg"
set PORT "$arg"
else
echo "Invalid port: $arg" >&2
return 1
end
end
end
end
set PROXY "$PROTO://$IP:$PORT"
echo set $OPT HTTP_PROXY $PROXY
echo set $OPT HTTPS_PROXY $PROXY
echo set $OPT ALL_PROXY $PROXY
echo set $OPT NO_PROXY localhost,127.0.0.1,::1
echo set $OPT http_proxy $PROXY
echo set $OPT https_proxy $PROXY
echo set $OPT all_proxy $PROXY
echo set $OPT no_proxy localhost,127.0.0.1,::1
end
function proxy_enable
source (__proxy_enable $argv | psub)
end
function proxy_disable
set -e -g HTTP_PROXY
set -e -g HTTPS_PROXY
set -e -g ALL_PROXY
set -e -g NO_PROXY
set -e -g http_proxy
set -e -g https_proxy
set -e -g all_proxy
set -e -g no_proxy
end