Skip to content

Commit

Permalink
feat: use functions instead aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
escalate committed Oct 6, 2018
1 parent 34833e3 commit eb438d1
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions proxy.plugin.zsh
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
_HTTP_PROXY=$(cat ${HOME}/.proxy/http_proxy)
_HTTPS_PROXY=$(cat ${HOME}/.proxy/https_proxy)
_FTP_PROXY=$(cat ${HOME}/.proxy/ftp_proxy)
_RSYNC_PROXY=$(cat ${HOME}/.proxy/rsync_proxy)
_NO_PROXY=$(cat ${HOME}/.proxy/no_proxy)

alias proxy="export http_proxy=${_HTTP_PROXY}; export HTTP_PROXY=${_HTTP_PROXY}; export https_proxy=${_HTTPS_PROXY}; export HTTPS_PROXY=${_HTTPS_PROXY}; export ftp_proxy=${_FTP_PROXY}; export FTP_PROXY=${_FTP_PROXY}; export rsync_proxy=${_RSYNC_PROXY}; export RSYNC_PROXY=${_RSYNC_PROXY}; export no_proxy=${_NO_PROXY}; export NO_PROXY=${_NO_PROXY}"
alias noproxy="unset http_proxy; unset HTTP_PROXY; unset https_proxy; unset HTTPS_PROXY; unset ftp_proxy; unset FTP_PROXY; unset rsync_proxy; unset RSYNC_PROXY; unset no_proxy; unset NO_PROXY"
_HTTP_PROXY=$(cat "${HOME}/.proxy/http_proxy")
_HTTPS_PROXY=$(cat "${HOME}/.proxy/https_proxy")
_FTP_PROXY=$(cat "${HOME}/.proxy/ftp_proxy")
_RSYNC_PROXY=$(cat "${HOME}/.proxy/rsync_proxy")
_NO_PROXY=$(cat "${HOME}/.proxy/no_proxy")

enable_proxy() {
export http_proxy="${_HTTP_PROXY}"
export HTTP_PROXY="${_HTTP_PROXY}"
export https_proxy="${_HTTPS_PROXY}"
export HTTPS_PROXY="${_HTTPS_PROXY}"
export ftp_proxy="${_FTP_PROXY}"
export FTP_PROXY="${_FTP_PROXY}"
export rsync_proxy="${_RSYNC_PROXY}"
export RSYNC_PROXY="${_RSYNC_PROXY}"
export no_proxy="${_NO_PROXY}"
export NO_PROXY="${_NO_PROXY}"
}

disable_proxy() {
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset ftp_proxy
unset FTP_PROXY
unset rsync_proxy
unset RSYNC_PROXY
unset no_proxy
unset NO_PROXY
}

list_proxy() {
echo "HTTP_PROXY=\"${_HTTP_PROXY}\""
echo "HTTPS_PROXY=\"${_HTTPS_PROXY}\""
echo "FTP_PROXY=\"${_FTP_PROXY}\""
echo "RSYNC_PROXY=\"${_RSYNC_PROXY}\""
echo "NO_PROXY=\"${_NO_PROXY}\""
}

# Aliases for backward compatibility
alias proxy=enable_proxy
alias noproxy=disable_proxy
alias lsproxy=list_proxy

0 comments on commit eb438d1

Please sign in to comment.