dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

zshrc (4785B)


      1 # -*- mode: shell-script; -*-
      2 # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
      3 # Initialization code that may require console input (password prompts, [y/n]
      4 # confirmations, etc.) must go above this block, everything else may go below.
      5 if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
      6   source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
      7 fi
      8 
      9 srcpath="$HOME/.dotfiles/shell"
     10 . "$srcpath"/env
     11 . "$srcpath"/paths
     12 unset srcpath
     13 export ZDOTDIR=$HOME/.config/zsh
     14 export HISTFILE=$ZDOTDIR/.zsh_history
     15 
     16 # ZSH-specific inits
     17 . "$DOTFILES"/shell/rc
     18 
     19 source_if_exists() { [ -f "$1" ] && . "$1"; }
     20 
     21 # Options
     22 if [ -n "$VIMRUNTIME" ]; then set -o vi
     23 else set -o emacs; fi
     24 
     25 setopt alwaystoend         # On completion, move cursor to end of word
     26 setopt autocd              # If I forget 'cd' before a path
     27 setopt autopushd           # Make cd push old directory onto stack
     28 setopt completeinword      # Completion from both ends of word
     29 setopt extendedhistory     # Save timestamp and duration of commands in histfile
     30 setopt interactivecomments # Allow comments
     31 setopt monitor             # Allow job control
     32 setopt nocaseglob          # Globs should be case insensitive
     33 setopt noflowcontrol       # Disable ^S and ^Q
     34 setopt promptsubst         # Parameter expansion, command subst, arithmetic expansion done in prompt
     35 setopt pushdignoredups     # Don't pushd duplicate directories
     36 setopt pushdminus          # Exchange meanings of + and - on directory stack
     37 
     38 # History options
     39 setopt sharehistory        # Import commands from histfile and append typed to histfile
     40 setopt appendhistory       # Append to history
     41 setopt incappendhistory    # Append immediately, not at shell exit
     42 setopt histexpiredupsfirst # When trimming history, remove duplicates first
     43 setopt histignoredups      # Don't save command into history if duplicate of previous
     44 setopt histignorespace     # Don't save command into history if starts with space
     45 setopt histfindnodups      # Ignore duplicates when searching
     46 setopt histreduceblanks    # Remove blank lines from history
     47 setopt histverify          # Show expansion first before executing
     48 
     49 # Enable extra completions
     50 fpath=($DOTFILES/shell/zsh-completions/src $DOTFILES/shell/osx-zsh-completions/ $DOTFILES/shell/zsh-completions-mine/ $fpath)
     51 autoload -Uz compinit && compinit
     52 source $DOTFILES/shell/oh-my-zsh-defaults/completion.zsh
     53 source $DOTFILES/shell/oh-my-zsh-defaults/directories.zsh
     54 source $DOTFILES/shell/oh-my-zsh-defaults/history.zsh
     55 source $DOTFILES/shell/oh-my-zsh-defaults/keys.zsh
     56 
     57 # Allow pasting bare URLs
     58 autoload -Uz url-quote-magic
     59 zle -N self-insert url-quote-magic
     60 autoload -Uz bracketed-paste-magic
     61 zle -N bracketed-paste bracketed-paste-magic
     62 
     63 # Auto correct commands, with exceptions (from oh-my-zsh)
     64 alias g='nocorrect git'
     65 alias git='nocorrect git'
     66 alias man='nocorrect man'
     67 alias sudo='nocorrect sudo'
     68 setopt correct
     69 setopt correct_all
     70 
     71 # Built-in Tetris (because why not)
     72 alias tetris="autoload -Uz tetriscurses && tetriscurses"
     73 
     74 # Powerlevel10k theme
     75 source_if_exists ~/.p10k.zsh
     76 source_if_exists $DOTFILES/shell/powerlevel10k/powerlevel10k.zsh-theme
     77 
     78 # FZF for fuzzy finding
     79 source_if_exists "$DOTFILES"/tools/fzf/shell/completion.zsh
     80 source_if_exists "$DOTFILES"/tools/fzf/shell/key-bindings.zsh
     81 source_if_exists "${XDG_CONFIG_HOME:-$HOME/.config}"/fzf/fzf.zsh
     82 
     83 # Ruby bundler plugin, automatically runs binstub in .bin or `bundle exec`s
     84 source_if_exists $DOTFILES/shell/zsh-plugins/bundler.plugin.zsh
     85 source_if_exists $DOTFILES/shell/zsh-plugins/gitignore.plugin.zsh
     86 source_if_exists $DOTFILES/shell/zsh-plugins/insulter.plugin.zsh
     87 
     88 insert-arg-of-prev-cmd() {
     89 : ${NUMERIC:-1}
     90 (( NUMERIC++ ))
     91 words=($(fc -ln -1))
     92 RBUFFER+="$words[$NUMERIC] "
     93 zle end-of-line
     94 }
     95 zle -N insert-arg-of-prev-cmd
     96 bindkey "\e^y" insert-arg-of-prev-cmd
     97 
     98 bindkey '\e#' pound-insert
     99 bindkey '^]' vi-find-next-char
    100 bindkey '\e^]' vi-find-prev-char
    101 bindkey -s '\el' '\C-e| less'
    102 bindkey -s '\e&' '\C-e&>/dev/null'
    103 
    104 bindkey -M menuselect 'h' vi-backward-char
    105 bindkey -M menuselect 'j' vi-down-line-or-history
    106 bindkey -M menuselect 'k' vi-up-line-or-history
    107 bindkey -M menuselect 'l' vi-forward-char
    108 bindkey -M menuselect 'left' vi-backward-char
    109 bindkey -M menuselect 'down' vi-down-line-or-history
    110 bindkey -M menuselect 'up' vi-up-line-or-history
    111 bindkey -M menuselect 'right' vi-forward-char
    112 
    113 # Bind lfcd (lf with cd) to ctrl-o
    114 bindkey -s '^o' '^ulfcd\n'
    115 
    116 _zsh_cli_fg() { fg; }
    117 zle -N _zsh_cli_fg
    118 bindkey '^Z' _zsh_cli_fg
    119 
    120 test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
    121 source_if_exists $DOTFILES/shell/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
    122 
    123 # Zoxide
    124 command -v zoxide &>/dev/null && eval "$(zoxide init zsh)"