.zshrc (3888B)
1 # .zshrc 2 3 # History. 4 [[ ! -d "$XDG_CACHE_HOME/zsh" ]] && mkdir -p "$XDG_CACHE_HOME/zsh" 5 HISTFILE="$XDG_CACHE_HOME/zsh/zsh_histfile" 6 HISTSIZE=10000 7 SAVEHIST=10000 8 9 # Write history command-by-command, don't overwrite. 10 setopt INC_APPEND_HISTORY 11 12 # Treat '#', '~', and '^' as part of patterns for filename generation. 13 setopt EXTENDED_GLOB 14 15 # vi-mode. 16 bindkey -v 17 bindkey '^Y' push-line 18 bindkey '^R' history-incremental-search-backward 19 20 # Add zsh completion definition dirs. 21 if [ -d "$HOME/.homebrew/share/zsh/site-functions" ]; then 22 fpath=("$HOME/.homebrew/share/zsh/site-functions" "${fpath[@]}") 23 fi 24 fpath=("$HOME/.local/zsh/site-functions" "$ZDOTDIR/site-functions" "${fpath[@]}") 25 26 # Specify where compinstall writes cfg commands. Default, but saves checks. 27 zstyle ':compinstall' filename "$ZDOTDIR/.zshrc" 28 29 # Use menu-style autocompletion. 30 zstyle ':completion:*' menu select 31 32 # Initialize completion for current session. The dump is regenerable cache, so 33 # it lives under XDG_CACHE_HOME alongside zsh_histfile. 34 zcompdump="$XDG_CACHE_HOME/zsh/zcompdump" 35 autoload -Uz compinit 36 if [[ -n $zcompdump(#qNmh-24) ]]; then 37 # zcompdump regenerated within the last 24 hours. 38 # Skip the `compaudit` check to speed things up. 39 compinit -C -d "$zcompdump" 40 else 41 compinit -d "$zcompdump" 42 fi 43 44 # Compile zcompdump to bytecode so subsequent shells load it via mmap instead 45 # of re-parsing the text dump. 46 if [[ -s $zcompdump && (! -s ${zcompdump}.zwc || $zcompdump -nt ${zcompdump}.zwc) ]]; then 47 zcompile -R -- ${zcompdump}.zwc $zcompdump 48 fi 49 unset zcompdump 50 51 # Current VCS branch (for prompt). Pure-shell, no forks: walks up from $PWD 52 # looking for .jj or .git, and reads .git/HEAD directly for the branch name. 53 vcs_branch() { 54 local d=$PWD 55 while [[ $d != / ]]; do 56 if [[ -d $d/.jj ]]; then 57 echo -n " ◉ " 58 return 59 fi 60 if [[ -e $d/.git ]]; then 61 local gitdir=$d/.git 62 # Worktrees / submodules: .git is a file containing "gitdir: <path>". 63 if [[ -f $gitdir ]]; then 64 local content=$(<$gitdir) 65 gitdir=${content#gitdir: } 66 [[ $gitdir == /* ]] || gitdir=$d/$gitdir 67 fi 68 local head 69 [[ -r $gitdir/HEAD ]] && head=$(<$gitdir/HEAD) 70 if [[ $head == ref:* ]]; then 71 local ref=${head#ref: } 72 echo -n " (${ref#refs/heads/})" 73 elif [[ -n $head ]]; then 74 echo -n " (${head[1,7]})" 75 fi 76 return 77 fi 78 d=${d:h} 79 done 80 } 81 82 # Prompt. 83 setopt prompt_subst 84 PROMPT='%F{yellow}%T %F{green}%n@%m%f:%B%F{blue}%c%b%F{yellow}$(vcs_branch)%f%# ' 85 86 # Set TERM for known terminals, and as a fallback when specified term is 87 # unavailable. 88 term_bin="" 89 if [[ -e /proc/$PPID/cmdline ]]; then 90 term_bin="${$(</proc/$PPID/cmdline):t}" 91 fi 92 if [[ "$COLORTERM" == "gnome-terminal" ]] || \ 93 [[ "$term_bin" == gnome-terminal* ]] || \ 94 [[ "$TERM" == "xterm-256color-italic" && ! $(tput -T"$TERM" longname > /dev/null 2>&1) ]]; then 95 export TERM=xterm-256color 96 fi 97 unset term_bin 98 99 # Load path additions. 100 if [ -f "$XDG_CONFIG_HOME/zsh/paths" ]; then 101 . "$XDG_CONFIG_HOME/zsh/paths" 102 fi 103 104 # Load aliases. 105 if [ -f "$XDG_CONFIG_HOME/zsh/aliases" ]; then 106 . "$XDG_CONFIG_HOME/zsh/aliases" 107 fi 108 109 # Load colour support. 110 if [ -f "$XDG_CONFIG_HOME/zsh/colors" ]; then 111 . "$XDG_CONFIG_HOME/zsh/colors" 112 fi 113 114 # Load custom functions. 115 if [ -f "$XDG_CONFIG_HOME/zsh/functions" ]; then 116 . "$XDG_CONFIG_HOME/zsh/functions" 117 fi 118 119 # If fzf is installed, enable it. Cache `fzf --zsh` output so we don't fork fzf 120 # on every shell startup; regenerate when the fzf binary is newer than the 121 # cached init script. 122 if (( $+commands[fzf] )); then 123 fzf_init="$XDG_CACHE_HOME/zsh/fzf-init.zsh" 124 if [[ ! -s $fzf_init || $commands[fzf] -nt $fzf_init ]]; then 125 fzf --zsh > $fzf_init 126 fi 127 . $fzf_init 128 unset fzf_init 129 fi 130 131 # Source any machine-local config. 132 if [[ -f "$HOME/.local/config/zsh/zshrc" ]]; then 133 . "$HOME/.local/config/zsh/zshrc" 134 fi