.dotfiles/zsh/.zshenv

93 lines
2.7 KiB
Bash
Executable file

#!/usr/bin/env zsh
# ------------------ Environment Setup ------------------
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export PAGER="less -i -N -S -R"
export EDITOR="nvim"
export BROWSER="/Applications/Zen.app/Contents/MacOS/zen"
# ------------------ Helper Functions ------------------
safe_path_add() {
[[ -d "$1" && ":$PATH:" != *":$1:"* ]] && export PATH="$1:$PATH"
}
# ------------------ Platform Detection ------------------
OS_TYPE="$(uname -s)"
ARCH="$(uname -m)"
# ------------------ macOS Setup ------------------
# macOS Homebrew and Toolchain Setup
if [[ "$OS_TYPE" == "Darwin" ]]; then
if [[ "$ARCH" == "arm64" ]]; then
export HOMEBREW_PREFIX="/opt/homebrew"
else
export HOMEBREW_PREFIX="/usr/local"
fi
safe_path_add "$HOMEBREW_PREFIX/bin"
safe_path_add "$HOMEBREW_PREFIX/sbin"
for dir in \
"$HOMEBREW_PREFIX/opt/coreutils/libexec/gnubin" \
"$HOMEBREW_PREFIX/opt/openssl@1.1/bin" \
"$HOMEBREW_PREFIX/opt/llvm/bin" \
"/Library/TeX/texbin" \
"$HOMEBREW_PREFIX/opt/rustup/bin"; do
safe_path_add "$dir"
done
# ------------------ Linux Setup ------------------
elif [[ "$OS_TYPE" == "Linux" ]]; then
safe_path_add "$HOME/.local/bin"
safe_path_add "$HOME/.cargo/bin"
safe_path_add "$HOME/.local/share/flatpak/exports/bin"
safe_path_add "/var/lib/flatpak/exports/bin"
[[ -d "/nix" ]] && safe_path_add "/nix/var/nix/profiles/default/bin"
# ------------------ WSL Detection ------------------
if grep -qEi "microsoft|wsl" /proc/version &>/dev/null; then
export IS_WSL=1
export BROWSER="wslview"
export DISPLAY="${DISPLAY:-:0}"
export WSL_HOST="$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')"
export NO_AT_BRIDGE=1
safe_path_add "/mnt/c/Windows/System32" # useful for calling Windows commands from WSL
fi
# ------------------ Remote Development Detection ------------------
if [[ -n "$SSH_CONNECTION" ]]; then
export IS_REMOTE=1
fi
if [[ -n "$CODESPACES" ]] || [[ -d "/workspaces" ]]; then
export IS_CODESPACES=1
safe_path_add "/workspaces/bin"
fi
fi
# ------------------ Common PATH ------------------
safe_path_add "$HOME/.local/bin/scripts"
# ------------------ Language Toolchains ------------------
# Python (pyenv)
export PYENV_ROOT="$HOME/.pyenv"
safe_path_add "$PYENV_ROOT/bin"
safe_path_add "$PYENV_ROOT/shims"
# Go
if command -v go &>/dev/null; then
export GOPATH="${GOPATH:-$HOME/.go}"
safe_path_add "$GOPATH/bin"
fi
# NVM
if [[ -d "$HOME/.nvm" ]]; then
export NVM_DIR="$HOME/.nvm"
[[ -s "$NVM_DIR/nvm.sh" ]] && . "$NVM_DIR/nvm.sh"
[[ -s "$NVM_DIR/zsh_completion" ]] && . "$NVM_DIR/bash_completion"
fi