Browse Source

Clean up zsh config

master
Taylor Bockman 1 week ago
parent
commit
5ac4fe4b0d
  1. 88
      dotfiles/zsh/exports.zsh
  2. 51
      dotfiles/zsh/macrc
  3. 8
      dotfiles/zsh/zshrc

88
dotfiles/zsh/exports.zsh

@ -1,58 +1,76 @@
#!/bin/zsh
if hash vim 2>/dev/null; then
# -------------------------
# Editor
# -------------------------
if command -v vim >/dev/null 2>&1; then
export EDITOR=vim
else
export EDITOR=vi
fi
if hash clang 2>/dev/null; then
export CC=$(which clang)
else
export CC=$(which gcc)
# -------------------------
# C / C++ compiler defaults
# -------------------------
if command -v clang >/dev/null 2>&1; then
export CC="$(command -v clang)"
elif command -v gcc >/dev/null 2>&1; then
export CC="$(command -v gcc)"
fi
if hash clang++ 2>/dev/null; then
export CXX=$(which clang++)
else
export CXX=$(which g++)
if command -v clang++ >/dev/null 2>&1; then
export CXX="$(command -v clang++)"
elif command -v g++ >/dev/null 2>&1; then
export CXX="$(command -v g++)"
fi
export OPENSSL_ROOT_DIR=$(which openssl)
# -------------------------
# History
# -------------------------
# Note: HISTCONTROL is bash-specific, but harmless.
# ZSH history dedupe should usually be configured with setopt elsewhere.
export HISTCONTROL=ignoredups
# Add openJDK to path
export PATH="/usr/local/opt/openjdk/bin:$PATH"
# -------------------------
# User paths
# -------------------------
path=("$HOME/bin" $path)
path=("$HOME/.local/bin" $path)
# Ignore duplicates in history to make history less of a hassle to use.
export HISTCONTROL=ignoredups
# -------------------------
# Go
# -------------------------
if command -v go >/dev/null 2>&1; then
export GOPATH="$HOME/.go"
path=("$(go env GOPATH)/bin" $path)
fi
# If go is installed, set the $GOPATH to the projects directory created above.
if which go > /dev/null; then
export GOPATH=$HOME/.go
export PATH=${PATH}:`go env GOPATH`/bin
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# If the Go install guide was followed for Linux,
# /usr/local/go will contain the go binary.
[[ -d "/usr/local/go/bin" ]] && path=("/usr/local/go/bin" $path)
fi
if [ -d "$HOME/.rvm" ]; then
export PATH="$PATH:$HOME/.rvm/bin"
# -------------------------
# Ruby / RVM
# -------------------------
if [[ -d "$HOME/.rvm/bin" ]]; then
path=("$HOME/.rvm/bin" $path)
fi
if [ -f "$HOME/.cargo/env" ]; then
# -----------------------------
# Rust / Cargo - Let rustup win
# -----------------------------
if [[ -f "$HOME/.cargo/env" ]]; then
. "$HOME/.cargo/env"
fi
if [[ "$OSTYPE" == "linux-gnu" ]]; then
# If the Go install guide was followed for Linux
# /usr/local/go will contain the go binary.
export PATH=$PATH:/usr/local/go/bin
if [[ -d "$HOME/.cargo/bin" ]]; then
path=("$HOME/.cargo/bin" $path)
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
# Enable homebrew openssl support
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
export PATH="/usr/local/opt/llvm/bin:$PATH"
export PATH="/usr/local/opt/qt/bin:$PATH"
export PATH="/usr/local/opt/tcl-tk/bin:$PATH"
# -------------------------
# OpenSSL fallback
# -------------------------
if command -v openssl >/dev/null 2>&1; then
export OPENSSL_BIN="$(command -v openssl)"
fi
export PATH=$HOME/bin:/usr/local/bin:$PATH

51
dotfiles/zsh/macrc

@ -0,0 +1,51 @@
#!/bin/zsh
# -------------------------
# macOS-specific setup
# -------------------------
# Prefer Apple Silicon Homebrew, fall back to Intel Homebrew.
if [[ -d "/opt/homebrew" ]]; then
export HOMEBREW_PREFIX="/opt/homebrew"
elif [[ -d "/usr/local/Homebrew" || -d "/usr/local/Cellar" ]]; then
export HOMEBREW_PREFIX="/usr/local"
fi
if [[ -n "$HOMEBREW_PREFIX" ]]; then
[[ -d "$HOMEBREW_PREFIX/bin" ]] && path=("$HOMEBREW_PREFIX/bin" $path)
[[ -d "$HOMEBREW_PREFIX/sbin" ]] && path=("$HOMEBREW_PREFIX/sbin" $path)
# LLVM / clangd / clang-format
if [[ -d "$HOMEBREW_PREFIX/opt/llvm/bin" ]]; then
path=("$HOMEBREW_PREFIX/opt/llvm/bin" $path)
export LDFLAGS="-L$HOMEBREW_PREFIX/opt/llvm/lib ${LDFLAGS:-}"
export CPPFLAGS="-I$HOMEBREW_PREFIX/opt/llvm/include ${CPPFLAGS:-}"
fi
# OpenSSL
if [[ -d "$HOMEBREW_PREFIX/opt/openssl@3" ]]; then
export OPENSSL_ROOT_DIR="$HOMEBREW_PREFIX/opt/openssl@3"
export LDFLAGS="-L$OPENSSL_ROOT_DIR/lib ${LDFLAGS:-}"
export CPPFLAGS="-I$OPENSSL_ROOT_DIR/include ${CPPFLAGS:-}"
export PKG_CONFIG_PATH="$OPENSSL_ROOT_DIR/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
elif [[ -d "$HOMEBREW_PREFIX/opt/openssl" ]]; then
export OPENSSL_ROOT_DIR="$HOMEBREW_PREFIX/opt/openssl"
export LDFLAGS="-L$OPENSSL_ROOT_DIR/lib ${LDFLAGS:-}"
export CPPFLAGS="-I$OPENSSL_ROOT_DIR/include ${CPPFLAGS:-}"
export PKG_CONFIG_PATH="$OPENSSL_ROOT_DIR/lib/pkgconfig:${PKG_CONFIG_PATH:-}"
fi
# OpenJDK
[[ -d "$HOMEBREW_PREFIX/opt/openjdk/bin" ]] && path=("$HOMEBREW_PREFIX/opt/openjdk/bin" $path)
# Qt
[[ -d "$HOMEBREW_PREFIX/opt/qt/bin" ]] && path=("$HOMEBREW_PREFIX/opt/qt/bin" $path)
# Tcl/Tk
[[ -d "$HOMEBREW_PREFIX/opt/tcl-tk/bin" ]] && path=("$HOMEBREW_PREFIX/opt/tcl-tk/bin" $path)
fi
# Ghostty CLI
if [[ -d "/Applications/Ghostty.app/Contents/MacOS" ]]; then
path=("/Applications/Ghostty.app/Contents/MacOS" $path)
fi

8
dotfiles/zsh/zshrc

@ -102,7 +102,7 @@ export PATH="$PATH:$HOME/.local/bin"
# Ocaml
test -r $HOME/.opam/opam-init/init.sh && . $HOME/.opam/opam-init/init.sh > /dev/null 2> /dev/null || true
# Rust
if [ -f "$HOME/.cargo/env" ]; then
. "$HOME/.cargo/env"
fi
# -------------------------
# Deduplicate PATH
# -------------------------
typeset -U path PATH

Loading…
Cancel
Save