From e46a370e2edfb5c6fe2caed7c34a3524cb7292cf Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sun, 5 Mar 2023 00:56:00 +0100 Subject: [PATCH] zsh: move environment setup to .zprofile --- config/zsh/.zprofile | 111 +++++++++++++++++++++++++++++++++++++++++++ config/zsh/.zshrc | 1 - config/zsh/env.zsh | 110 ------------------------------------------ 3 files changed, 111 insertions(+), 111 deletions(-) delete mode 100644 config/zsh/env.zsh diff --git a/config/zsh/.zprofile b/config/zsh/.zprofile index 59b431d..ead3eda 100644 --- a/config/zsh/.zprofile +++ b/config/zsh/.zprofile @@ -1,3 +1,4 @@ +# General environment settings. export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" @@ -6,4 +7,114 @@ export LANG="en_US.UTF-8" export LANGUAGE="en_US" export LC_ALL="en_US.UTF-8" export LC_CTYPE="en_US.UTF-8" +export LC_COLLATE="C" + +export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc" +export LESS="-i -j.49 -M -R -z-2" +export LESSHISTFILE="$XDG_DATA_HOME/less/history" +export LESSHISTSIZE=1000 +export LOCAL_PREFIX="/usr/local" +export PAGER=less +export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py" + +# Make man pages pretty, but only if $TERM is set because otherwise `tput` +# would report errors (e.g., when running a command via SSH without allocating +# a pty $TERM is not set). +[ -n "$TERM" ] && { + rst="$(tput sgr0)" + LESS_TERMCAP_md="$(printf '%s\n' 'setaf 3' | tput -S)" + LESS_TERMCAP_mb="$LESS_TERMCAP_md" + LESS_TERMCAP_me="$rst" + LESS_TERMCAP_us="$(printf '%s\n' 'setaf 7' 'smul' | tput -S)" + LESS_TERMCAP_ue="$rst" + LESS_TERMCAP_so="$(printf '%s\n' 'setaf 4' 'setab 0' | tput -S)" + LESS_TERMCAP_se="$rst" + export LESS_TERMCAP_md LESS_TERMCAP_mb LESS_TERMCAP_me + export LESS_TERMCAP_us LESS_TERMCAP_ue LESS_TERMCAP_so LESS_TERMCAP_se + export GROFF_NO_SGR=1 + unset rst +} + +# Prevent path_helper from messing with the PATH when starting tmux. +# +# Clearing PATH before path_helper executes (from /etc/profile) will prevent it +# from prepending the default PATH to our (previously) chosen PATH, and will +# allow the rest of this file to set up PATH and MANPATH correctly. +# +# For details see: https://superuser.com/a/583502 +# +[ "$(uname -s)" = "Darwin" ] && { PATH=""; source /etc/profile; } + +# Add custom bin dirs to PATH if they exist and are not already in PATH. +while read -r dir; do + [ -d "$dir" ] || continue # skip if directory doesn't exist + case ":${PATH:=$dir}:" in + *:"$dir":*) ;; # already in PATH -> ignore + *) PATH="$dir:$PATH" ;; # not yet in PATH -> prepend it + esac +done </dev/null 2>&1 && MANPATH="$(unset MANPATH; manpath)" +while read -r dir; do + [ -d "$dir" ] || continue # skip if directory doesn't exist + case ":${MANPATH:=$dir}:" in + *:"$dir":*) ;; # already in MANPATH -> ignore + *) MANPATH="$dir:$MANPATH" ;; # not yet in MANPATH -> prepend it + esac +done </dev/null 2>&1; then + export EDITOR="nvim" +else + export EDITOR="vim" +fi + +if command -v brew >/dev/null 2>&1; then + export HOMEBREW_NO_ANALYTICS=1 + export HOMEBREW_NO_AUTO_UPDATE=1 +fi + +# Set $DISPLAY if running in WSL and an Xserver is reachable +# +# How to configure Windows Firewall for Xserver: https://skeptric.com/wsl2-xserver/ +# How to check if running in WSL: https://stackoverflow.com/a/61014411 +if [ -n "$(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip')" ]; then + xdisplay="$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf 2>/dev/null):0.0" + if command -v xset >/dev/null 2>&1; then + if DISPLAY="$xdisplay" timeout '0.2s' xset q >/dev/null 2>&1; then + export DISPLAY="$xdisplay" + export LIBGL_ALWAYS_INDIRECT=1 + fi + fi + unset xdisplay +fi diff --git a/config/zsh/.zshrc b/config/zsh/.zshrc index fed7da1..c66bbac 100644 --- a/config/zsh/.zshrc +++ b/config/zsh/.zshrc @@ -1,5 +1,4 @@ # Set up zsh for interactive use (options, prompt, aliases, etc.) -source "$ZDOTDIR/env.zsh" # This one needs to go first. source "$ZDOTDIR/aliases.zsh" source "$ZDOTDIR/completion.zsh" source "$ZDOTDIR/history.zsh" diff --git a/config/zsh/env.zsh b/config/zsh/env.zsh deleted file mode 100644 index 4de4dba..0000000 --- a/config/zsh/env.zsh +++ /dev/null @@ -1,110 +0,0 @@ -# General environment settings. -export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc" -export LESS="-i -j.49 -M -R -z-2" -export LESSHISTFILE="$XDG_DATA_HOME/less/history" -export LESSHISTSIZE=1000 -export LOCAL_PREFIX="/usr/local" -export PAGER=less -export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/startup.py" - -# Make man pages pretty, but only if $TERM is set because otherwise `tput` -# would report errors (e.g., when running a command via SSH without allocating -# a pty $TERM is not set). -[ -n "$TERM" ] && { - rst="$(tput sgr0)" - LESS_TERMCAP_md="$(printf '%s\n' 'setaf 3' | tput -S)" - LESS_TERMCAP_mb="$LESS_TERMCAP_md" - LESS_TERMCAP_me="$rst" - LESS_TERMCAP_us="$(printf '%s\n' 'setaf 7' 'smul' | tput -S)" - LESS_TERMCAP_ue="$rst" - LESS_TERMCAP_so="$(printf '%s\n' 'setaf 4' 'setab 0' | tput -S)" - LESS_TERMCAP_se="$rst" - export LESS_TERMCAP_md LESS_TERMCAP_mb LESS_TERMCAP_me - export LESS_TERMCAP_us LESS_TERMCAP_ue LESS_TERMCAP_so LESS_TERMCAP_se - export GROFF_NO_SGR=1 - unset rst -} - -# Prevent path_helper from messing with the PATH when starting tmux. -# -# Clearing PATH before path_helper executes (from /etc/profile) will prevent it -# from prepending the default PATH to our (previously) chosen PATH, and will -# allow the rest of this file to set up PATH and MANPATH correctly. -# -# For details see: https://superuser.com/a/583502 -# -[ "$(uname -s)" = "Darwin" ] && { PATH=""; source /etc/profile; } - -# Add custom bin dirs to PATH if they exist and are not already in PATH. -while read -r dir; do - [ -d "$dir" ] || continue # skip if directory doesn't exist - case ":${PATH:=$dir}:" in - *:"$dir":*) ;; # already in PATH -> ignore - *) PATH="$dir:$PATH" ;; # not yet in PATH -> prepend it - esac -done </dev/null 2>&1 && MANPATH="$(unset MANPATH; manpath)" -while read -r dir; do - [ -d "$dir" ] || continue # skip if directory doesn't exist - case ":${MANPATH:=$dir}:" in - *:"$dir":*) ;; # already in MANPATH -> ignore - *) MANPATH="$dir:$MANPATH" ;; # not yet in MANPATH -> prepend it - esac -done </dev/null 2>&1; then - export EDITOR="nvim" -else - export EDITOR="vim" -fi - -if command -v brew >/dev/null 2>&1; then - export HOMEBREW_NO_ANALYTICS=1 - export HOMEBREW_NO_AUTO_UPDATE=1 -fi - -# Set $DISPLAY if running in WSL and an Xserver is reachable -# -# How to configure Windows Firewall for Xserver: https://skeptric.com/wsl2-xserver/ -# How to check if running in WSL: https://stackoverflow.com/a/61014411 -if [ -n "$(uname -r | sed -n 's/.*\( *Microsoft *\).*/\1/ip')" ]; then - xdisplay="$(awk '/nameserver/ {print $2; exit}' /etc/resolv.conf 2>/dev/null):0.0" - if command -v xset >/dev/null 2>&1; then - if DISPLAY="$xdisplay" timeout '0.2s' xset q >/dev/null 2>&1; then - export DISPLAY="$xdisplay" - export LIBGL_ALWAYS_INDIRECT=1 - fi - fi - unset xdisplay -fi -