diff --git a/.zprofile b/.zprofile deleted file mode 100644 index 154d258..0000000 --- a/.zprofile +++ /dev/null @@ -1,47 +0,0 @@ -# ─< proxy config >─────────────────────────────────────────────────────────────────────── -proxy() { - local ip="172.22.11.69" - local port="8080" - - if [ -z "$1" ]; then - echo "Usage: proxy [--show|--set]" - echo " --show Show current proxy settings" - echo " --set Set proxy to $ip:$port" - return 0 - fi - - case "$1" in - --show) - echo "These are your proxy configurations:" - echo "http: $http_proxy, HTTP: $HTTP_PROXY" - echo "https: $https_proxy, HTTPS: $HTTPS_PROXY" - ;; - --set) - # Check if the IP and port are reachable - if nc -z -w5 $ip $port; then - # If reachable, set the proxy environment variables - export http_proxy="http://$ip:$port" - export https_proxy="http://$ip:$port" - export HTTP_PROXY="http://$ip:$port" - export HTTPS_PROXY="http://$ip:$port" - echo_info "Proxy set to: http://$ip:$port" || echo "Proxy set to: http://$ip:$port" - else - echo_error "IP $ip with port $port is not reachable." || echo "IP $ip with port $port is not reachable." - fi - ;; - *) - echo "Invalid option! Use --show or --set." - ;; - esac -} - -# ─< unset proxy >──────────────────────────────────────────────────────────────────────── -noproxy() { - unset {HTTP_PROXY,HTTPS_PROXY,http_proxy,https_proxy} -} - -if ping -w2 -q swu.dom; then - proxy -else - noproxy -fi diff --git a/.zshenv b/.zshenv index 0b85ff6..ff1ca9a 100644 --- a/.zshenv +++ b/.zshenv @@ -30,7 +30,9 @@ command_exists() { command -v "$@" >/dev/null 2>&1 } -# ─< paths >────────────────────────────────────────────────────────────────────────────── +# ╭───────╮ +# │ paths │ +# ╰───────╯ if [ -d "$HOME/.local/bin" ]; then export PATH="$HOME/.local/bin:$PATH" if [ -e "$HOME/.local/bin/lazydocker" ]; then @@ -49,13 +51,13 @@ else } fi -# ─< go bin path >──────────────────────────────────────────────────────────────────────── +# ─────────────────────────────────────< go bin path >─────────────────────────────────── [ -d "$HOME/go/bin" ] && { export PATH="$HOME/go/bin:$PATH" echo_info "Go programs at $HOME/go/bin/" } -# ─< cargo bin path >───────────────────────────────────────────────────────────────────── +# ────────────────────────────────────< cargo bin path >──────────────────────────────────── if [ -e "$HOME/.cargo/env" ]; then echo_info "Loadet $HOME/.cargo/env" . "$HOME/.cargo/env" @@ -66,9 +68,60 @@ else } fi -# bun completions -# [ -s "$HOME/.bun/_bun" ] && . "$HOME/.bun/_bun" -# [ -s "$HOME/.bun/_bun" ] && export BUN_INSTALL="$HOME/.bun" && export PATH="$BUN_INSTALL/bin:$PATH" +# ──────────────────────────────────────< fzf plugin >────────────────────────────────────── +[ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] && + export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH" -# ─< fzf plugin >───────────────────────────────────────────────────────────────────────── -[ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] && export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH" +# ╭──────────────╮ +# │ proxy config │ +# ╰──────────────╯ +# ─────────────────────────────────────< unset proxy >─────────────────────────────────── +noproxy() { + unset {HTTP_PROXY,HTTPS_PROXY,http_proxy,https_proxy} +} + +# ──────────────────< proxy function to set or show the proxy variables >──────────────── +proxy() { + local ip="172.22.11.69" + local port="8080" + + if [ -z "$1" ]; then + echo "Usage: proxy [--show|--set]" + echo " --show Show current proxy settings" + echo " --set Set proxy to $ip:$port" + return 0 + fi + + case "$1" in + --show) + echo "These are your proxy configurations:" + echo "http: ${http_proxy}, HTTP: ${HTTP_PROXY}" + echo "https: ${https_proxy}, HTTPS: ${HTTPS_PROXY}" + ;; + --set) + # ─< Check if the IP and port are reachable >───────────────────────────────────────────── + if nc -z -w5 $ip $port; then + # ─< If reachable, set the proxy environment variables >────────────────────────────────── + local proxy="http://${ip}:${port}" + export http_proxy="${proxy}" + export https_proxy="${proxy}" + export HTTP_PROXY="${proxy}" + export HTTPS_PROXY="${proxy}" + echo "Proxy set to: http://$ip:$port" + else + echo "IP $ip with port $port is not reachable." + fi + ;; + *) + echo "Invalid option! Use --show or --set." + ;; + esac +} + +# ────────────< check network availability and set proxy if in correct network >──────────── +noproxy +if ping -w2 -q swu.dom; then + proxy --set +else + noproxy +fi