From 23b381166da1ecdb7888efa49e8e9cf01fbfb5c3 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Mon, 21 Oct 2024 17:33:28 +0800 Subject: [PATCH] =?UTF-8?q?shell=20=E4=BB=A3=E7=90=86=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=8F=90=E5=8F=96=E5=88=B0=20.bash=5Fproxy.s?= =?UTF-8?q?h=20=E6=96=87=E4=BB=B6=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dot/.bash_proxy.sh | 50 ++++++++++++++++++++++++++++++++++++++++++ dot/.bashrc | 54 +++++----------------------------------------- 2 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 dot/.bash_proxy.sh diff --git a/dot/.bash_proxy.sh b/dot/.bash_proxy.sh new file mode 100644 index 0000000..a632e09 --- /dev/null +++ b/dot/.bash_proxy.sh @@ -0,0 +1,50 @@ +HTTP_PROXY="http://192.168.1.13:20172" +SOCKS_PROXY="socks5://192.168.1.13:20170" + +set-shell-proxy() { + export http_proxy="$HTTP_PROXY" + export https_proxy="$HTTP_PROXY" +} + +unset-shell-proxy() { + unset http_proxy + unset https_proxy +} + +set-git-proxy() { + prefix_cmd="" + flag="--global" + if [[ "$1" == "-s" ]]; then + prefix_cmd="sudo" + flag="--system" + elif [[ "$1" == "-l" ]]; then + flag="--local" + fi + + $prefix_cmd git config $flag http.proxy $HTTP_PROXY + $prefix_cmd git config $flag http.sslVerify false +} + +unset-git-proxy() { + prefix_cmd="" + flag="--global" + if [[ "$1" == "-s" ]]; then + prefix_cmd="sudo" + flag="--system" + elif [[ "$1" == "-l" ]]; then + flag="--local" + fi + + $prefix_cmd git config $flag --unset http.proxy + $prefix_cmd git config $flag --unset http.sslVerify +} + +set-npm-proxy() { + npm config set proxy $HTTP_PROXY + npm config set https-proxy $HTTP_PROXY +} + +unset-npm-proxy() { + npm config delete proxy + npm config delete https-proxy +} diff --git a/dot/.bashrc b/dot/.bashrc index 2e450e1..fd335f1 100644 --- a/dot/.bashrc +++ b/dot/.bashrc @@ -30,54 +30,10 @@ alias la="ls -a" alias lh="ls -lh" alias lha="ls -lha" - -set-proxy() { - export http_proxy=http://127.0.0.1:8118 - export https_proxy=http://127.0.0.1:8118 -} - -unset-proxy() { - unset http_proxy - unset https_proxy -} - -set-git-proxy() { - prefix_cmd="" - flag="--global" - if [[ "$1" == "-s" ]]; then - prefix_cmd="sudo" - flag="--system" - elif [[ "$1" == "-l" ]]; then - flag="--local" - fi - - $prefix_cmd git config $flag http.proxy http://127.0.0.1:8118 - $prefix_cmd git config $flag http.sslVerify false -} - -unset-git-proxy() { - prefix_cmd="" - flag="--global" - if [[ "$1" == "-s" ]]; then - prefix_cmd="sudo" - flag="--system" - elif [[ "$1" == "-l" ]]; then - flag="--local" - fi - - $prefix_cmd git config $flag --unset http.proxy - $prefix_cmd git config $flag --unset http.sslVerify -} - -set-npm-proxy() { - npm config set proxy http://127.0.0.1:8118 - npm config set https-proxy http://127.0.0.1:8118 -} - -unset-npm-proxy() { - npm config delete proxy - npm config delete https-proxy -} +PROXY_SHELL_FILE="$(realpath ~/.bash_proxy.sh)" +if [[ -e $PROXY_SHELL_FILE ]] ; then + . $PROXY_SHELL_FILE +fi if [[ "${TERM}" != "tmux-256color" ]] && [[ -x $(type -p tmux) ]]; then tmux @@ -91,7 +47,7 @@ alias pip='function _pip() { };_pip' # pnpm -export PNPM_HOME="/home/zedhugh/.local/share/pnpm" +export PNPM_HOME="$(realpath ~/.local/share/pnpm)" export PATH="$PNPM_HOME:$PATH" # pnpm end # tabtab source for packages