From 7d490453085ae084ce0e3875952eae1d3ad7b1ab Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 26 Jan 2026 16:57:37 -0600 Subject: refactor(shell): reorganize shell config for proper separation Restructure shell configuration to follow standard conventions: - .profile: Environment variables only (POSIX compatible) - .bash_profile: NEW - sources .profile and .bashrc for login shells - .bashrc: Bash-specific settings, sources .bashrc.d/ - .zshrc: Zsh-specific settings, sources .zshrc.d/ New modular directories: - .bashrc.d/: aliases, emacs, fzf, git, media, utilities - .zshrc.d/: same as bashrc.d plus arch-downgrade (zsh-only) - .profile.d/: reduced to env-only files (display, framework, auto-tmux) Fixes: - Remove duplicate .profile sourcing in .bashrc - Remove broken XDG_CURRENT_DESKTOP=GNOME line from display.sh - Move aliases/functions from .profile to appropriate .d/ directories - Shell-specific init (zoxide, fzf) now in .bashrc/.zshrc directly - FreeBSD bindkey fix now in .zshrc directly Also adds CLAUDE.md session context file. Co-Authored-By: Claude Opus 4.5 --- dotfiles/system/.zshrc | 259 ++++++++++++++++++++++++++----------------------- 1 file changed, 140 insertions(+), 119 deletions(-) (limited to 'dotfiles/system/.zshrc') diff --git a/dotfiles/system/.zshrc b/dotfiles/system/.zshrc index 413d8b8..0e997ab 100644 --- a/dotfiles/system/.zshrc +++ b/dotfiles/system/.zshrc @@ -1,55 +1,66 @@ -# source appropriate dotfiles if they exist -[ -f ~/.profile ] && source ~/.profile -[ -f ~/.secrets ] && source ~/.secrets -[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh -[ -f ~/.zsh/fzf-tab.zsh ] && source ~/.zsh/fzf-tab.zsh - - -# GENERAL ##################### -setopt PROMPT_SUBST # allow env variables in prompt -setopt AUTO_REMOVE_SLASH # self explicit -setopt CHASE_LINKS # resolve symlinks -setopt CORRECT # try to correct spelling of commands -setopt EXTENDED_GLOB # activate complex pattern globbing -setopt GLOB_DOTS # include dotfiles in globbing -setopt PRINT_EXIT_VALUE # print return value if non-zero -setopt CLOBBER # don't need to use >| to truncate existing files -setopt interactivecomments # allow comments in command line like bash -unsetopt BEEP # no bell on error -unsetopt BG_NICE # no lower prio for background jobs -unsetopt HIST_BEEP # no bell on error in history -unsetopt HUP # no hup signal at shell exit -unsetopt IGNORE_EOF # do not exit on end-of-file -unsetopt LIST_BEEP # no bell on ambiguous completion -unsetopt RM_STAR_SILENT # ask for confirmation for `rm *' or `rm path/*' -autoload -U colors zsh-mime-setup select-word-style -colors # colors -zsh-mime-setup # run everything as if it's an executable +# .zshrc +# Craig Jennings +# +# Zsh-specific interactive shell settings. +# Aliases, functions, prompt, completions, shell options. + +# ============================================================================= +# Environment Variables (from .profile) +# ============================================================================= +[ -f "$HOME/.profile" ] && source "$HOME/.profile" +[ -f "$HOME/.secrets" ] && source "$HOME/.secrets" + +# ============================================================================= +# General Options +# ============================================================================= +setopt PROMPT_SUBST # allow variable substitution in prompt +setopt AUTO_REMOVE_SLASH # remove trailing slash when completing +setopt CHASE_LINKS # resolve symlinks +setopt CORRECT # try to correct spelling of commands +setopt EXTENDED_GLOB # activate complex pattern globbing +setopt GLOB_DOTS # include dotfiles in globbing +setopt PRINT_EXIT_VALUE # print return value if non-zero +setopt CLOBBER # allow > to truncate existing files +setopt INTERACTIVE_COMMENTS # allow comments in command line +unsetopt BEEP # no bell on error +unsetopt BG_NICE # no lower prio for background jobs +unsetopt HIST_BEEP # no bell on error in history +unsetopt HUP # no hup signal at shell exit +unsetopt IGNORE_EOF # do not exit on end-of-file +unsetopt LIST_BEEP # no bell on ambiguous completion +unsetopt RM_STAR_SILENT # ask for confirmation for `rm *' +autoload -U colors zsh-mime-setup select-word-style +colors +zsh-mime-setup -# HISTORY ##################### +# ============================================================================= +# History +# ============================================================================= HISTFILE="$HOME/.zsh_history" HISTSIZE=10000000 SAVEHIST=$HISTSIZE -setopt BANG_HIST # Treat the '!' character specially during expansion. -setopt EXTENDED_HISTORY # Write the history file in the ":start:elapsed;command" format. -setopt INC_APPEND_HISTORY # Write to the history file immediately, not when the shell exits. -setopt SHARE_HISTORY # Share history between all sessions. -setopt HIST_EXPIRE_DUPS_FIRST # Expire duplicate entries first when trimming history. -setopt HIST_IGNORE_DUPS # Don't record an entry that was just recorded again. -setopt HIST_IGNORE_ALL_DUPS # Delete old recorded entry if new entry is a duplicate. -setopt HIST_FIND_NO_DUPS # Do not display a line previously found. -setopt HIST_IGNORE_SPACE # Don't record an entry starting with a space. -setopt HIST_SAVE_NO_DUPS # Don't write duplicate entries in the history file. -setopt HIST_REDUCE_BLANKS # Remove superfluous blanks before recording entry. -setopt HIST_VERIFY # Don't execute immediately upon history expansion. -setopt HIST_BEEP # Beep when accessing nonexistent history. - -# KEYBOARD ################## -# create a zkbd compatible hash; -# to add other keys to this hash, see: man 5 terminfo -typeset -g -A key +setopt BANG_HIST # treat '!' specially during expansion +setopt EXTENDED_HISTORY # write history with timestamps +setopt INC_APPEND_HISTORY # write to history immediately +setopt SHARE_HISTORY # share history between sessions +setopt HIST_EXPIRE_DUPS_FIRST +setopt HIST_IGNORE_DUPS +setopt HIST_IGNORE_ALL_DUPS +setopt HIST_FIND_NO_DUPS +setopt HIST_IGNORE_SPACE # don't record entries starting with space +setopt HIST_SAVE_NO_DUPS +setopt HIST_REDUCE_BLANKS +setopt HIST_VERIFY # don't execute immediately on history expansion + +# ============================================================================= +# Keyboard Bindings +# ============================================================================= +bindkey -e # emacs keybindings + +# zkbd compatible hash for special keys +typeset -g -A key key[Home]="${terminfo[khome]}" key[End]="${terminfo[kend]}" key[Insert]="${terminfo[kich1]}" @@ -63,7 +74,6 @@ key[PageUp]="${terminfo[kpp]}" key[PageDown]="${terminfo[knp]}" key[Shift-Tab]="${terminfo[kcbt]}" -# setup key accordingly [[ -n "${key[Home]}" ]] && bindkey -- "${key[Home]}" beginning-of-line [[ -n "${key[End]}" ]] && bindkey -- "${key[End]}" end-of-line [[ -n "${key[Insert]}" ]] && bindkey -- "${key[Insert]}" overwrite-mode @@ -77,43 +87,43 @@ key[Shift-Tab]="${terminfo[kcbt]}" [[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history [[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete -# cjennings additions ################# -bindkey -e # emacs keybindings -bindkey '\e[1;5C' forward-word # C-Right -bindkey '\e[1;5D' backward-word # C-Left -bindkey -s "\e[24~" "" # stop F12 from spitting tildes +bindkey '\e[1;5C' forward-word # Ctrl-Right +bindkey '\e[1;5D' backward-word # Ctrl-Left +bindkey -s "\e[24~" "" # stop F12 from outputting tildes -# Finally, make sure the terminal is in application mode, when zle is -# active. Only then are the values from $terminfo valid. +# Terminal application mode for proper key handling if (( ${+terminfo[smkx]} && ${+terminfo[rmkx]} )); then - autoload -Uz add-zle-hook-widget - function zle_application_mode_start { echoti smkx } - function zle_application_mode_stop { echoti rmkx } - add-zle-hook-widget -Uz zle-line-init zle_application_mode_start - add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop + autoload -Uz add-zle-hook-widget + function zle_application_mode_start { echoti smkx } + function zle_application_mode_stop { echoti rmkx } + add-zle-hook-widget -Uz zle-line-init zle_application_mode_start + add-zle-hook-widget -Uz zle-line-finish zle_application_mode_stop fi -# COMPLETION ################## -autoload -U compinit -compinit -zmodload -i zsh/complist -setopt AUTO_LIST # list options on ambiguous completion -setopt AUTO_MENU # show menu on second request for completion -setopt ALWAYS_TO_END # when completing from middle of a word, move cursor to end of word -setopt COMPLETE_IN_WORD # allow completion from within a word/phrase -setopt COMPLETEALIASES # complete alisases -setopt CORRECT # spelling correction for commands -setopt HASH_LIST_ALL # hash everything before completion -setopt LIST_AMBIGUOUS # complete as much of a completion until it gets - -zstyle ':completion::complete:*' use-cache on # completion caching, use rehash to clear -zstyle ':completion:*' cache-path ~/.zsh/cache # cache path -zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' # ignore case -zstyle ':completion:*' menu select=2 # menu if nb items > 2 -zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} # colorz ! -zstyle ':completion:*::::' completer _expand _complete _ignored _approximate # list of completers to use - -# sections completion +# FreeBSD delete key fix +[[ "$(uname)" == "FreeBSD" ]] && bindkey "\e[3~" delete-char + +# ============================================================================= +# Completion +# ============================================================================= +autoload -U compinit && compinit +zmodload -i zsh/complist + +setopt AUTO_LIST # list options on ambiguous completion +setopt AUTO_MENU # show menu on second tab +setopt ALWAYS_TO_END # move cursor to end after completion +setopt COMPLETE_IN_WORD # allow completion from within a word +setopt COMPLETE_ALIASES # complete aliases +setopt HASH_LIST_ALL # hash everything before completion +setopt LIST_AMBIGUOUS # complete as much as possible + +zstyle ':completion::complete:*' use-cache on +zstyle ':completion:*' cache-path ~/.zsh/cache +zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}' # case insensitive +zstyle ':completion:*' menu select=2 +zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS} +zstyle ':completion:*::::' completer _expand _complete _ignored _approximate + zstyle ':completion:*' verbose yes zstyle ':completion:*:descriptions' format $'\e[00;34m%d' zstyle ':completion:*:messages' format $'\e[00;31m%d' @@ -126,54 +136,65 @@ zstyle ':completion:*:kill:*' force-list always zstyle ':completion:*:*:kill:*:processes' list-colors "=(#b) #([0-9]#)*=29=34" zstyle ':completion:*:*:killall:*' menu yes select zstyle ':completion:*:killall:*' force-list always -users=(cjennings root) # because I don't care about others -zstyle ':completion:*' users $users +zstyle ':completion:*' users cjennings root -#generic completion with --help compdef _gnu_generic gcc compdef _gnu_generic gdb -# DIRECTORY NAVIGATION ######## -setopt AUTO_CD # if typing directory name, auto cd there -setopt AUTO_PUSHD # push old directories to stack (for use with popd) -setopt PUSHD_IGNORE_DUPS # don’t push multiple copies of same directory onto stack -setopt PUSHD_SILENT # don't print directory stack after pushd/popd -setopt PUSHD_TO_HOME # pushd == `pushd $HOME` - -# VERSION CONTROL -autoload -Uz vcs_info # Load version control information -precmd() { vcs_info } - -# Styling the version control info -zstyle ':vcs_info:*' enable git cvs svn # enable only the repo systems I use -zstyle ':vcs_info:*' check-for-changes false # don't check for changes in local repo -zstyle ':vcs_info:git*' formats "on %b" # format the vcs_info_msg_0_ variable - -# HISTORY #################### -export HISTFILE=~/.zsh_history -export HISTFILESIZE=1000000000 -export HISTSIZE=1000000000 -setopt INC_APPEND_HISTORY -export HISTTIMEFORMAT="[%F %T] " -setopt EXTENDED_HISTORY -setopt HIST_IGNORE_ALL_DUPS +# Python Poetry completions +fpath+=~/.zfunc -# PROMPT ##################### +# ============================================================================= +# Directory Navigation +# ============================================================================= +setopt AUTO_CD # cd by typing directory name +setopt AUTO_PUSHD # push old directories to stack +setopt PUSHD_IGNORE_DUPS # don't push duplicates +setopt PUSHD_SILENT # don't print stack after pushd/popd +setopt PUSHD_TO_HOME # pushd with no args goes home + +# ============================================================================= +# Version Control Info (for prompt) +# ============================================================================= +autoload -Uz vcs_info +precmd() { vcs_info } +zstyle ':vcs_info:*' enable git cvs svn +zstyle ':vcs_info:*' check-for-changes false +zstyle ':vcs_info:git*' formats "on %b" + +# ============================================================================= +# Prompt +# ============================================================================= WHO='%n' NEWLINE=$'\n' -PROMPT='[%D %*] $WHO $HOST:${PWD/#$HOME/~} %(?..[%?] ) $NEWLINE%# ' +PROMPT='[%D %*] $WHO $HOST:${PWD/#$HOME/~} %(?..[%?] )$NEWLINE%# ' RPROMPT='${vcs_info_msg_0_}' -# PYTHON POETRY ############# -fpath+=~/.zfunc -autoload -Uz compinit && compinit +# ============================================================================= +# Source modular zsh configs from .zshrc.d/ +# ============================================================================= +if [[ -d "$HOME/.zshrc.d" ]]; then + for file in "$HOME/.zshrc.d"/*.sh; do + [[ -r "$file" ]] && source "$file" + done + unset file +fi + +# ============================================================================= +# Tool-specific initialization +# ============================================================================= +# FZF +[[ -f "$HOME/.fzf.zsh" ]] && source "$HOME/.fzf.zsh" +[[ -f "$HOME/.zsh/fzf-tab.zsh" ]] && source "$HOME/.zsh/fzf-tab.zsh" -# zoxide -eval "$(zoxide init zsh)" +# Dart CLI completion +[[ -f "$HOME/.config/.dart-cli-completion/zsh-config.zsh" ]] && \ + source "$HOME/.config/.dart-cli-completion/zsh-config.zsh" -## [Completion] -## Completion scripts setup. Remove the following line to uninstall -[[ -f /home/cjennings/.config/.dart-cli-completion/zsh-config.zsh ]] && . /home/cjennings/.config/.dart-cli-completion/zsh-config.zsh || true -## [/Completion] +# Zoxide (smart cd) +command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init zsh)" -ulimit -c unlimited \ No newline at end of file +# ============================================================================= +# Resource Limits +# ============================================================================= +ulimit -c unlimited -- cgit v1.2.3