# .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 # ============================================================================= HISTFILE="$HOME/.zsh_history" HISTSIZE=10000000 SAVEHIST=$HISTSIZE 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]}" key[Backspace]="${terminfo[kbs]}" key[Delete]="${terminfo[kdch1]}" key[Up]="${terminfo[kcuu1]}" key[Down]="${terminfo[kcud1]}" key[Left]="${terminfo[kcub1]}" key[Right]="${terminfo[kcuf1]}" key[PageUp]="${terminfo[kpp]}" key[PageDown]="${terminfo[knp]}" key[Shift-Tab]="${terminfo[kcbt]}" [[ -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 [[ -n "${key[Backspace]}" ]] && bindkey -- "${key[Backspace]}" backward-delete-char [[ -n "${key[Delete]}" ]] && bindkey -- "${key[Delete]}" delete-char [[ -n "${key[Up]}" ]] && bindkey -- "${key[Up]}" up-line-or-history [[ -n "${key[Down]}" ]] && bindkey -- "${key[Down]}" down-line-or-history [[ -n "${key[Left]}" ]] && bindkey -- "${key[Left]}" backward-char [[ -n "${key[Right]}" ]] && bindkey -- "${key[Right]}" forward-char [[ -n "${key[PageUp]}" ]] && bindkey -- "${key[PageUp]}" beginning-of-buffer-or-history [[ -n "${key[PageDown]}" ]] && bindkey -- "${key[PageDown]}" end-of-buffer-or-history [[ -n "${key[Shift-Tab]}" ]] && bindkey -- "${key[Shift-Tab]}" reverse-menu-complete 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 # 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 fi # 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' zstyle ':completion:*' group-name '' zstyle ':completion:*:manuals' separate-sections true zstyle ':completion:*:processes' command 'ps -au$USER' zstyle ':completion:*:*:kill:*' menu yes select 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 zstyle ':completion:*' users cjennings root compdef _gnu_generic gcc compdef _gnu_generic gdb # Python Poetry completions fpath+=~/.zfunc # ============================================================================= # 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%# ' RPROMPT='${vcs_info_msg_0_}' # ============================================================================= # 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" # Dart CLI completion [[ -f "$HOME/.config/.dart-cli-completion/zsh-config.zsh" ]] && \ source "$HOME/.config/.dart-cli-completion/zsh-config.zsh" # Zoxide (smart cd) command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init zsh)" # ============================================================================= # Resource Limits # ============================================================================= ulimit -c unlimited