# .zshrc function
function useproxy() {
local PORT="7890"
if [ -n "$1" ]; then
PORT="$1"
fi
local proxy="
http://127.0.0.1:$PORT"
export https_proxy="$proxy"
export http_proxy="$proxy"
echo -e "\033[32m已临时设置 https_proxy、http_proxy 使用 $proxy 进行代理\033[0m"
}
function unproxy() {
export https_proxy=""
export http_proxy=""
echo -e "\033[32m已取消 https_proxy、http_proxy 代理设置\033[0m"
}
function usenode() {
local p=""
declare -A node_dirs=(
["12"]="$(realpath ~/Applications/node12)"
["12.10.0"]="$(realpath ~/Applications/node-v12.10.0-darwin-x64)"
["14"]="$(realpath ~/Applications/node14)"
["16"]="$(realpath ~/Applications/node16)"
["18"]="$(realpath ~/Applications/node18)"
["20"]="$(realpath ~/Applications/node20)"
)
if [[ -n "${node_dirs[$1]}" ]]; then
p="${node_dirs[$1]}/bin"
export PATH="$p:$PATH"
echo -e "\033[32m已临时将 $p 拼接到了PATH前面\033[0m"
echo "\n$PATH"
echo "\n\033[32mnode -v\033[0m"
node -v
else
echo -e "\033[31m命令无效!可用的命令如下:\033[0m"
for key in ${(k)node_dirs}; do
echo -e "\033[32musenode $key\033[0m"
done
fi
}