dotfiles/.zshrc
Claude 291a5faffb
feat: control WezTerm appearance from .zshrc via generated env.lua
All user-tunable knobs now live in one block at the top of .zshrc:
KANAGAWA_THEME, WEZTERM_FONT_SIZE, WEZTERM_WINDOW_OPACITY,
WEZTERM_TEXT_OPACITY.

GUI-launched WezTerm never inherits shell exports (which is why
WEZTERM_THEME silently did nothing on desktop launches). Reuse the
existing tmux current-theme.conf pattern: .zshrc writes the values to
~/.config/wezterm/env.lua (only when they change), and wezterm.lua
dofile()s it and registers it in the config reload watch list — so
editing .zshrc and opening a new shell restyles the running window.

Precedence in wezterm.lua: env.lua > process env > defaults.
env.lua is gitignored (machine-local, generated).
2026-06-11 15:41:59 +00:00

142 lines
4.8 KiB
Bash

# Homebrew (Linux) — must come first so brew-installed tools and plugin
# paths below resolve.
if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
# ===================== User-tunable environment ========================
# Single place to control the look of the whole stack. Everything below
# (and the wezterm env.lua writer further down) derives from these.
export KANAGAWA_THEME="${KANAGAWA_THEME:-wave}" # wave | dragon
export WEZTERM_FONT_SIZE="${WEZTERM_FONT_SIZE:-16}"
export WEZTERM_WINDOW_OPACITY="${WEZTERM_WINDOW_OPACITY:-0.80}"
export WEZTERM_TEXT_OPACITY="${WEZTERM_TEXT_OPACITY:-1.0}"
# ========================================================================
# Theme (kanagawa variants: dragon|wave)
case "${KANAGAWA_THEME}" in
wave|kanagawa-wave)
export TMUX_THEME="wave"
export NVIM_THEME="wave"
export STARSHIP_THEME="wave"
export WEZTERM_THEME="wave"
export STARSHIP_CONFIG="$HOME/.config/starship/starship-wave.toml"
;;
*)
export TMUX_THEME="dragon"
export NVIM_THEME="dragon"
export STARSHIP_THEME="dragon"
export WEZTERM_THEME="dragon"
export STARSHIP_CONFIG="$HOME/.config/starship/starship.toml"
;;
esac
# Write a deterministic tmux theme selector file so tmux servers don't depend
# on inherited shell env vars.
export TMUX_THEME_FILE="$HOME/.config/tmux/current-theme.conf"
mkdir -p "$HOME/.config/tmux"
if [ "$TMUX_THEME" = "wave" ]; then
printf 'source-file %s\n' "$HOME/.config/tmux/wave-theme.conf" >| "$TMUX_THEME_FILE"
else
printf 'source-file %s\n' "$HOME/.config/tmux/dragon-theme.conf" >| "$TMUX_THEME_FILE"
fi
# Write WezTerm settings file (same pattern as tmux above). GUI-launched
# WezTerm never sees shell exports, so it watches this file and live-reloads
# when the values change.
_wez_env_file="$HOME/.config/wezterm/env.lua"
_wez_env_content="return {
theme = \"$WEZTERM_THEME\",
font_size = $WEZTERM_FONT_SIZE,
window_opacity = $WEZTERM_WINDOW_OPACITY,
text_opacity = $WEZTERM_TEXT_OPACITY,
}"
mkdir -p "$HOME/.config/wezterm"
if [ ! -f "$_wez_env_file" ] || [ "$(cat "$_wez_env_file")" != "$_wez_env_content" ]; then
printf '%s\n' "$_wez_env_content" >| "$_wez_env_file"
fi
unset _wez_env_file _wez_env_content
# Starship
if command -v starship >/dev/null 2>&1; then
eval "$(starship init zsh)"
fi
# zoxide - a better cd command
if command -v zoxide >/dev/null 2>&1; then
eval "$(zoxide init zsh)"
fi
# Syntax highlighting (try Debian/Ubuntu path first, then Arch)
for _p in \
/usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh \
/usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
do
[ -f "$_p" ] && source "$_p" && break
done
# Disable underline
(( ${+ZSH_HIGHLIGHT_STYLES} )) || typeset -A ZSH_HIGHLIGHT_STYLES
ZSH_HIGHLIGHT_STYLES[path]=none
ZSH_HIGHLIGHT_STYLES[path_prefix]=none
# Autosuggestions
for _p in \
/usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh \
/usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
do
[ -f "$_p" ] && source "$_p" && break
done
# ------------FZF--------------
export FZF_DEFAULT_COMMAND="fd --hidden --strip-cwd-prefix --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type=d --hidden --strip-cwd-prefix --exclude .git"
export FZF_DEFAULT_OPTS="--height 50% --layout=default --border --color=hl:#2dd4bf"
export FZF_CTRL_T_OPTS="--preview 'bat --color=always -n --line-range :500 {}'"
export FZF_ALT_C_OPTS="--preview 'eza --icons=always --tree --color=always {} | head -200'"
export FZF_TMUX_OPTS=" -p90%,70% "
# fzf key bindings and completion (apt uses /usr/share/doc/fzf/examples)
for _p in \
/usr/share/doc/fzf/examples/key-bindings.zsh \
/usr/share/fzf/key-bindings.zsh
do
[ -f "$_p" ] && source "$_p" && break
done
for _p in \
/usr/share/doc/fzf/examples/completion.zsh \
/usr/share/fzf/completion.zsh
do
[ -f "$_p" ] && source "$_p" && break
done
unset _p
# -----------------------------
unalias lt 2>/dev/null
lt() {
local level=${1:-3}
shift
eza --tree --all --level "$level" "$@"
}
# aliases
alias zshconfig="nvim ~/.zshrc"
alias nvimconfig="nvim ~/.config/nvim"
alias dev="cd $HOME/Documents"
alias ls="eza --no-filesize --long --color=always --icons=always --no-user"
alias ll="eza -lah --group-directories-first --no-filesize --long --color=always --icons=always --no-user"
alias vim="nvim"
alias crq="cargo run -q"
alias sudo="sudo "
alias lg="lazygit"
alias update="brew upgrade && sudo apt update && sudo apt upgrade -y"
if command -v tmux &>/dev/null && [ -z "$TMUX" ]; then
tmux attach -t default 2>/dev/null || tmux new -s default
fi
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"