From 0b3326e6f5b639cff96eedf3dafe665f5ac2d595 Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Tue, 9 Oct 2012 09:06:17 +0200 Subject: [PATCH 1/2] Added proxy plugin for enabling/disabling proxy settings in Bash, Git, npm and SSH config. --- plugins/available/proxy.plugin.bash | 248 ++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 plugins/available/proxy.plugin.bash diff --git a/plugins/available/proxy.plugin.bash b/plugins/available/proxy.plugin.bash new file mode 100644 index 00000000..a7c2be10 --- /dev/null +++ b/plugins/available/proxy.plugin.bash @@ -0,0 +1,248 @@ +cite about-plugin +about-plugin 'Proxy Tools' + +disable_proxy () +{ + about 'Disables proxy settings for Bash, npm and SSH' + group 'proxy' + + unset http_proxy + unset https_proxy + echo "Disabled proxy environment variables" + + npm_disable_proxy + ssh_disable_proxy +} + +enable_proxy () +{ + about 'Enables proxy settings for Bash, npm and SSH' + group 'proxy' + + export http_proxy=$BASH_IT_HTTP_PROXY + export https_proxy=$BASH_IT_HTTPS_PROXY + echo "Enabled proxy environment variables" + + npm_enable_proxy + ssh_enable_proxy +} + +show_proxy () +{ + about 'Shows the proxy settings for Bash, Git, npm and SSH' + group 'proxy' + + echo "" + echo "Environment Variables" + echo "=====================" + env | grep "proxy" + + bash_it_show_proxy + npm_show_proxy + git_global_show_proxy + ssh_show_proxy +} + +proxy_help () +{ + about 'Provides an overview of the bash-it proxy configuration' + group 'proxy' + + echo "" + echo "bash-it uses the variables BASH_IT_HTTP_PROXY and BASH_IT_HTTPS_PROXY to set the shell's" + echo "proxy settings when you call 'enable_proxy'. These variables are best defined in a custom" + echo "script in bash-it's custom script folder ($BASH_IT/custom)," + echo "e.g. $BASH_IT/custom/proxy.env.bash" + + bash_it_show_proxy +} + +bash_it_show_proxy () +{ + about 'Shows the bash-it proxy settings' + group 'proxy' + + echo "" + echo "bash-it Environment Variables" + echo "=============================" + echo "(These variables will be used to set the proxy when you call 'enable_proxy')" + echo "" + env | grep -e "BASH_IT.*PROXY" +} + +npm_show_proxy () +{ + about 'Shows the npm proxy settings' + group 'proxy' + + if $(command -v npm &> /dev/null) ; then + echo "" + echo "npm" + echo "===" + echo "npm HTTP proxy: " `npm config get proxy` + echo "npm HTTPS proxy: " `npm config get https-proxy` + fi +} + +npm_disable_proxy () +{ + about 'Disables npm proxy settings' + group 'proxy' + + if $(command -v npm &> /dev/null) ; then + npm config delete proxy + npm config delete https-proxy + echo "Disabled npm proxy settings" + fi +} + +npm_enable_proxy () +{ + about 'Enables npm proxy settings' + group 'proxy' + + if $(command -v npm &> /dev/null) ; then + npm config set proxy $BASH_IT_HTTP_PROXY + npm config set https-proxy $BASH_IT_HTTPS_PROXY + echo "Enabled npm proxy settings" + fi +} + +git_global_show_proxy () +{ + about 'Shows global Git proxy settings' + group 'proxy' + + if $(command -v git &> /dev/null) ; then + echo "" + echo "Git (Global Settings)" + echo "=====================" + echo "Git (Global) HTTP proxy: " `git config --global --get http.proxy` + echo "Git (Global) HTTPS proxy: " `git config --global --get https.proxy` + fi +} + +git_global_disable_proxy () +{ + about 'Disables global Git proxy settings' + group 'proxy' + + if $(command -v git &> /dev/null) ; then + git config --global --unset-all http.proxy + git config --global --unset-all https.proxy + echo "Disabled global Git proxy settings" + fi +} + +git_global_enable_proxy () +{ + about 'Enables global Git proxy settings' + group 'proxy' + + if $(command -v git &> /dev/null) ; then + git_global_disable_proxy + + git config --global --add http.proxy $BASH_IT_HTTP_PROXY + git config --global --add https.proxy $BASH_IT_HTTPS_PROXY + echo "Enabled global Git proxy settings" + fi +} + +git_show_proxy () +{ + about 'Shows current Git project proxy settings' + group 'proxy' + + if $(command -v git &> /dev/null) ; then + echo "Git Project Proxy Settings" + echo "=====================" + echo "Git HTTP proxy: " `git config --get http.proxy` + echo "Git HTTPS proxy: " `git config --get https.proxy` + fi +} + +git_disable_proxy () +{ + about 'Disables current Git project proxy settings' + group 'proxy' + + if $(command -v git &> /dev/null) ; then + git config --unset-all http.proxy + git config --unset-all https.proxy + echo "Disabled Git project proxy settings" + fi +} + +git_enable_proxy () +{ + about 'Enables current Git project proxy settings' + group 'proxy' + + if $(command -v git &> /dev/null) ; then + git_disable_proxy + + git config --add http.proxy $BASH_IT_HTTP_PROXY + git config --add https.proxy $BASH_IT_HTTPS_PROXY + echo "Enabled Git project proxy settings" + fi +} + +ssh_show_proxy () +{ + about 'Shows SSH config proxy settings (from ~/.ssh/config)' + group 'proxy' + + if [ -f ~/.ssh/config ] ; then + echo "" + echo "SSH Config Enabled in ~/.ssh/config" + echo "===================================" + awk ' + $1 == "Host" { + host = $2; + next; + } + $1 == "ProxyCommand" { + $1 = ""; + printf "%s\t%s\n", host, $0 + } + ' ~/.ssh/config | column -t + + echo "" + echo "SSH Config Disabled in ~/.ssh/config" + echo "====================================" + awk ' + $1 == "Host" { + host = $2; + next; + } + $0 ~ "^#.*ProxyCommand.*" { + $1 = ""; + $2 = ""; + printf "%s\t%s\n", host, $0 + } + ' ~/.ssh/config | column -t + fi +} + +ssh_disable_proxy () +{ + about 'Disables SSH config proxy settings' + group 'proxy' + + if [ -f ~/.ssh/config ] ; then + sed -e's/^.*ProxyCommand/# ProxyCommand/' -i "" ~/.ssh/config + echo "Disabled SSH config proxy settings" + fi +} + + +ssh_enable_proxy () +{ + about 'Enables SSH config proxy settings' + group 'proxy' + + if [ -f ~/.ssh/config ] ; then + sed -e's/# ProxyCommand/ ProxyCommand/' -i "" ~/.ssh/config + echo "Enabled SSH config proxy settings" + fi +} From 8c55d659668a680f77e81d72a7031af26e49a1fe Mon Sep 17 00:00:00 2001 From: Nils Winkler Date: Sat, 3 Nov 2012 20:47:40 +0100 Subject: [PATCH 2/2] Added ALL_PROXY variable. --- plugins/available/proxy.plugin.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/available/proxy.plugin.bash b/plugins/available/proxy.plugin.bash index a7c2be10..3d05d79c 100644 --- a/plugins/available/proxy.plugin.bash +++ b/plugins/available/proxy.plugin.bash @@ -8,6 +8,7 @@ disable_proxy () unset http_proxy unset https_proxy + unset ALL_PROXY echo "Disabled proxy environment variables" npm_disable_proxy @@ -21,6 +22,7 @@ enable_proxy () export http_proxy=$BASH_IT_HTTP_PROXY export https_proxy=$BASH_IT_HTTPS_PROXY + export ALL_PROXY=$BASH_IT_HTTP_PROXY echo "Enabled proxy environment variables" npm_enable_proxy @@ -36,6 +38,7 @@ show_proxy () echo "Environment Variables" echo "=====================" env | grep "proxy" + env | grep "ALL_PROXY" bash_it_show_proxy npm_show_proxy