Files
dotfiles/.zshrc
2026-01-27 21:29:44 +01:00

145 lines
4.6 KiB
Bash

# Basic
export LANG=en_US.UTF-8
export EDITOR=vim
export HISTFILE=~/.zhistory
export HISTSIZE=100000
export SAVEHIST=100000
# History behavior
setopt INC_APPEND_HISTORY SHARE_HISTORY
setopt HIST_IGNORE_ALL_DUPS HIST_REDUCE_BLANKS
setopt HIST_VERIFY
# General quality-of-life
setopt EXTENDED_GLOB
setopt INTERACTIVE_COMMENTS
setopt MULTIOS # pipe to multiple outputs
setopt AUTO_PUSHD # cd becomes pushd
setopt AUTO_NAME_DIRS # use named dirs when possible
setopt GLOB_COMPLETE # expand globs
setopt ZLE
setopt NO_FLOW_CONTROL # disable Ctrl-S
setopt CLOBBER # allow > to overwrite
setopt NO_CASE_GLOB # case insensitive globbing
setopt NUMERIC_GLOB_SORT
setopt RC_EXPAND_PARAM # better array expansion
unsetopt AUTO_CD # don't run directories as commands
unsetopt CORRECT # no "did you mean?"
unsetopt BANG_HIST # no ! history expansion
# modules
zmodload zsh/datetime
zmodload zsh/mathfunc
# plugin manager
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}}/.zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "${ZINIT_HOME}/zinit.zsh"
zinit light zsh-users/zsh-autosuggestions
zinit light zsh-users/zsh-syntax-highlighting
zinit light zsh-users/zsh-completions
# completions
autoload -Uz compinit
compinit
zstyle ':completion:*' menu select
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# key definitions (terminfo + common codes)
typeset -gA key
key[Home]="${terminfo[khome]}"
key[End]="${terminfo[kend]}"
key[Delete]="${terminfo[kdch1]}"
key[Up]="${terminfo[kcuu1]}"
key[Down]="${terminfo[kcud1]}"
key[ShiftTab]="${terminfo[kcbt]}"
key[CtrlLeft]="^[[1;5D"
key[CtrlRight]="^[[1;5C"
# keybindings
bindkey -e
[[ -n ${key[Home]} ]] && bindkey ${key[Home]} beginning-of-line
[[ -n ${key[End]} ]] && bindkey ${key[End]} end-of-line
[[ -n ${key[Delete]} ]] && bindkey ${key[Delete]} delete-char
[[ -n ${key[ShiftTab]} ]] && bindkey ${key[ShiftTab]} reverse-menu-complete
[[ -n ${key[CtrlLeft]} ]] && bindkey ${key[CtrlLeft]} backward-word
[[ -n ${key[CtrlRight]} ]] && bindkey ${key[CtrlRight]} forward-word
bindkey '^[.' insert-last-word # Esc,. (last arg of prev cmd)
bindkey '^[b' backward-word # Alt+B
bindkey '^[f' forward-word # Alt+F
bindkey '^[^?' backward-kill-word # Alt+Backspace
bindkey '^Q' push-line # Ctrl+Q (stash line, type another, comes back)
autoload -Uz edit-command-line && zle -N edit-command-line
bindkey '^X^E' edit-command-line # Ctrl+X,E → edit in $EDITOR
# search from prefix
zinit light zsh-users/zsh-history-substring-search
[[ -n ${key[Up]} ]] && bindkey ${key[Up]} history-substring-search-up
[[ -n ${key[Down]} ]] && bindkey ${key[Down]} history-substring-search-down
# starship prompt
export STARSHIP_CONFIG=~/.starship.toml
zinit ice as"command" from"gh-r" \
atclone"./starship init zsh > init.zsh; ./starship completions zsh > _starship" \
atpull"%atclone" src"init.zsh"
zinit light starship/starship
# async dotfiles pull (once/day, after prompt)
zinit ice wait'1' silent nocompile atload'
local marker=~/.cache/.dotfiles-pull
[[ -f $marker && $(($(date +%s) - $(stat -c %Y $marker))) -lt 86400 ]] && return
mkdir -p ~/.cache && touch $marker
git --git-dir=$HOME/.dotgit/ --work-tree=$HOME pull --ff-only -q 2>/dev/null
'
zinit light zdharma-continuum/null
# paths
typeset -U path
path=(
$HOME/.local/bin
$HOME/.cargo/bin
$path
)
# fzf (if available)
if (( $+commands[fzf] )); then
source <(fzf --zsh 2>/dev/null) || {
# fallback for older fzf versions
[[ -f ~/.fzf.zsh ]] && source ~/.fzf.zsh
[[ -f /usr/share/fzf/key-bindings.zsh ]] && source /usr/share/fzf/key-bindings.zsh
[[ -f /usr/share/fzf/completion.zsh ]] && source /usr/share/fzf/completion.zsh
}
export FZF_DEFAULT_OPTS='--height 40% --reverse'
fi
# aliases: git
alias g="git"
alias a="git add --all :/"
alias b="git branch"
alias c="git commit -am"
alias ch="git checkout"
alias pull="git pull"
alias rb="git reset HEAD --hard"
alias s="git status"
alias st="git stash"
alias dc="a && c 'wip'"
# aliases: dotfiles (bare repo)
alias .g='git --git-dir=$HOME/.dotgit/ --work-tree=$HOME'
alias .gs='.g status -uno'
alias .gp='.g commit -am "auto" && .g push'
# aliases: tmux
alias tmuxr="tmux new-session -A -s auto"
alias tmuxn="tmux new-session -A -s auto \; new-window"
alias tmuxa="tmux new-session -A -s"
# aliases: misc
alias zshreload="exec zsh"
alias -g LATEST='*(om[1])' # glob: most recently modified
alias FUNCTION_PRELUDE="setopt LOCAL_OPTIONS PIPE_FAIL XTRACE ERR_RETURN"