zsh/.zshenv

152 lines
5.6 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# ───────────────────────────────────< Message storage >─────────────────────────────────
typeset -A _MESSAGES
_MESSAGES=(
[error]=""
[warn]=""
[info]=""
)
# Define color variables
RED='\033[0;31m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Functions to store messages
echo_error() {
_MESSAGES[error]+="${RED}$1${NC}\n"
}
echo_warning() {
_MESSAGES[warn]+="${YELLOW}⚠️ $1${NC}\n"
}
echo_info() {
_MESSAGES[info]+="${CYAN} $1${NC}\n"
}
# ─< Check if the given command exists silently >─────────────────────────────────────────
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# ╭───────╮
# │ paths │
# ╰───────╯
if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
if [ -e "$HOME/.local/bin/lazydocker" ]; then
alias ld="$HOME/.local/bin/lazydocker"
fi
fi
if command_exists nvim; then
export EDITOR="nvim"
else
# ─< linux binary via script installation >───────────────────────────────────────────────
[ -d "$HOME/.bin/nvim-linux64/bin" ] && {
export PATH="$HOME/.bin/nvim-linux64/bin:$PATH"
export EDITOR="$HOME/.bin/nvim-linux64/bin/nvim"
echo_info "neovim at $HOME/.bin/nvim-linux64/bin/nvim"
}
fi
# ─────────────────────────────────────< go bin path >───────────────────────────────────
[ -d "$HOME/go/bin" ] && {
export PATH="$HOME/go/bin:$PATH"
echo_info "Go programs at $HOME/go/bin/"
}
# ────────────────────────────────────< cargo bin path >────────────────────────────────────
if [ -e "$HOME/.cargo/env" ]; then
echo_info "Loadet $HOME/.cargo/env"
. "$HOME/.cargo/env"
else
[ -d "$HOME/.cargo/bin" ] && {
export PATH="$HOME/.cargo/bin:$PATH"
echo_info "Cargo programs at $HOME/.cargo/bin/"
}
fi
# ──────────────────────────────────────< fzf plugin >──────────────────────────────────────
[ -d "$HOME/.zsh/plugins/fzf-zsh-plugin/bin" ] &&
export PATH="$HOME/.zsh/plugins/fzf-zsh-plugin/bin:$PATH"
# ──────────────────────────────────────< git config >──────────────────────────────────────
getGitDir() {
if [[ -d "$HOME/Dokumente/git/forgejo" ]]; then
export GIT="$HOME/Dokumente/git/forgejo"
return 0
elif [[ -d "$HOME/git" ]]; then
[ -d "$HOME/git/forgejo" ] &&
export GIT="$HOME/git/forgejo" &&
return 0
export GIT="$HOME/git"
return 0
fi
}
if command_exists git; then
[ -z "$GIT" ] &&
getGitDir
fi
# ╭──────────────╮
# │ 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:"
if [ -n "${http_proxy}" ] || [ -n "${HTTP_PROXY}" ] || [ -n "${https_proxy}" ] || [ -n "${HTTPS_PROXY}" ]; then
echo "http: ${http_proxy}| HTTP: ${HTTP_PROXY}"
echo "https: ${https_proxy}| HTTPS: ${HTTPS_PROXY}"
else
echo "No proxy configured."
fi
;;
--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 -c 1 -W 2 swu.dom &>/dev/null; then
proxy --set
else
noproxy
fi