# Basic mkdir -p ~/.vim/{undo,swap,backup} 2>/dev/null export LANG=en_US.UTF-8 export EDITOR=vim export HISTFILE=~/.zhistory export HISTSIZE=100000 export SAVEHIST=100000 # History behavior setopt EXTENDED_HISTORY INC_APPEND_HISTORY SHARE_HISTORY setopt HIST_IGNORE_ALL_DUPS 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 zmodload zsh/stat # 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 bindkey '^[e' edit-command-line # Alt+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 ZLE_RPROMPT_INDENT=0 # 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) { sleep 1 local marker=~/.cache/.dotfiles-pull [[ -f $marker && $((EPOCHSECONDS - $(zstat +mtime $marker))) -lt 86400 ]] && return mkdir -p ~/.cache && touch $marker git --git-dir=$HOME/.dotgit/ --work-tree=$HOME pull --ff-only -q 2>/dev/null } &! # paths typeset -U path path=( $HOME/.local/bin $HOME/.cargo/bin /usr/local/go/bin $HOME/go/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 # ls defaults if (( $+commands[dircolors] )); then [[ -z "$LS_COLORS" ]] && eval "$(dircolors --sh)" alias ls='ls --group-directories-first --color=auto' else alias ls='ls -F' 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" # yazi wrapper (cd to dir on exit) function y() { local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" cwd command yazi "$@" --cwd-file="$tmp" IFS= read -r -d '' cwd < "$tmp" [ "$cwd" != "$PWD" ] && [ -d "$cwd" ] && builtin cd -- "$cwd" rm -f -- "$tmp" } # functions function mkcd { : "${1:?where?}" [[ -e $1 ]] && { echo "file exists"; return 1 } mkdir -p $1 && cd $1 } function cdtmp { local dir="${HOME}/tmp/auto_$(date +%Y_%m_%d_%H_%M_%S)" [[ -n "$1" ]] && dir="${dir}_$1" mkcd "$dir" } # 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"