zsh: refactor configuration with focus on interactive shells

Moved most of the work to `.zshrc' rather than `.zhenv', because most of
my configuration is only relevant to my interactive use of the shell.
This commit is contained in:
Fernando Schauenburg 2022-10-21 19:59:16 +02:00
parent 07d45f7a8b
commit 39f51775fe
9 changed files with 59 additions and 91 deletions

5
config/zsh/.zprofile Normal file
View file

@ -0,0 +1,5 @@
export LANG="en_US.UTF-8"
export LANGUAGE="en_US"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"

View file

@ -1,23 +1,11 @@
#!/bin/zsh
# Set up zsh for interactive use (options, prompt, aliases, etc.) # Set up zsh for interactive use (options, prompt, aliases, etc.)
source "$ZDOTDIR/env.zsh" # This one needs to go first.
# On MacOS, manipulate PATH and MANPATH here (see explanation in .zshenv). source "$ZDOTDIR/aliases.zsh"
[ "$(uname -s)" = "Darwin" ] && source "$XDG_CONFIG_HOME/shell/path.sh" source "$ZDOTDIR/completion.zsh"
source "$ZDOTDIR/history.zsh"
# Source additional configurations if available. source "$ZDOTDIR/prompt.zsh"
while read -r f; do [ -f "$f" ] && source "$f"; done <<EOL source "$ZDOTDIR/vi-mode.zsh"
$ZDOTDIR/aliases
$ZDOTDIR/completion
$ZDOTDIR/prompt
$ZDOTDIR/vi-mode
EOL
unset f
# Prevent ctrl-s from freezing the terminal. # Prevent ctrl-s from freezing the terminal.
stty stop undef stty stop undef
# Save a lot of history.
HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history"
HISTSIZE=1000000
SAVEHIST=1000000

View file

@ -1,5 +1,3 @@
#!/bin/sh
# ls: make `ls` group directories first if supported. # ls: make `ls` group directories first if supported.
# lsc: force `ls` to use color output (e.g. for piping into `less`). # lsc: force `ls` to use color output (e.g. for piping into `less`).
if command -v exa >/dev/null 2>&1; then if command -v exa >/dev/null 2>&1; then

View file

@ -1,5 +1,3 @@
#!/bin/zsh
autoload -Uz compinit && compinit autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}'
zstyle ':completion:*' menu select zstyle ':completion:*' menu select

View file

@ -1,5 +1,29 @@
# This file is meant to be sourced from either $ZDOTDIR/.zshenv or # General environment settings.
# $ZDOTDIR/.zshrc (see those files for explanation). 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. # Prevent path_helper from messing with the PATH when starting tmux.
# #
@ -50,7 +74,7 @@ export MANPATH
unset dir unset dir
# These checks habe to be done after PATH manipulation above so we can find # These checks have to be done after PATH manipulation above so we can find
# installed programs if they are in the added paths. # installed programs if they are in the added paths.
if command -v nvim >/dev/null 2>&1; then if command -v nvim >/dev/null 2>&1; then
@ -64,3 +88,18 @@ if command -v brew >/dev/null 2>&1; then
export HOMEBREW_NO_AUTO_UPDATE=1 export HOMEBREW_NO_AUTO_UPDATE=1
fi 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

4
config/zsh/history.zsh Normal file
View file

@ -0,0 +1,4 @@
HISTFILE="${XDG_DATA_HOME:-$HOME/.local/share}/zsh/history"
HISTSIZE=1000000
SAVEHIST=1000000

View file

@ -1,5 +1,3 @@
#!/bin/zsh
base03=8 base02=0 base01=10 base00=11 base0=12 base1=14 base2=7 base3=15 base03=8 base02=0 base01=10 base00=11 base0=12 base1=14 base2=7 base3=15
red=1 orange=9 yellow=3 green=2 cyan=6 blue=4 violet=13 magenta=5 red=1 orange=9 yellow=3 green=2 cyan=6 blue=4 violet=13 magenta=5

View file

@ -1,5 +1,3 @@
#!/bin/zsh
# Use vi mode for line editing. # Use vi mode for line editing.
bindkey -v bindkey -v
export KEYTIMEOUT=1 export KEYTIMEOUT=1

View file

@ -1,68 +1,8 @@
#!/bin/sh
# Environment variables are set here for login shells.
# Keep things organized. # Keep things organized.
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}" export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}" export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}" export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
# General environment settings. # Everything else will be configured from within $ZDOTDIR.
export INPUTRC="$XDG_CONFIG_HOME/readline/inputrc" export ZDOTDIR="${ZDOTDIR:-$XDG_CONFIG_HOME/zsh}"
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 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"
export ZDOTDIR="$XDG_CONFIG_HOME/zsh"
# 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
}
# Add custom directories to PATH and MANPATH.
#
# On MacOS, we skip it here because these relevant files are sourced in order
# by zsh on startup ($ZDOTDIR defaults to $HOME if not set):
#
# $ZDOTDIR/.zshenv <-- This file.
# /etc/zprofile <-- On MacOS this sources /usr/libexec/path_helper,
# which would undo what we do here.
# $ZDOTDIR/.zshrc <-- So we defer our PATH manipulation to this file.
#
# shellcheck disable=SC1090
[ "$(uname -s)" = "Darwin" ] || . "$XDG_CONFIG_HOME/shell/path.sh"
# 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