summaryrefslogtreecommitdiff
path: root/dotfiles/system/.zshrc
blob: 0e997aba3f3056c871a5abe70e688ac5f06dcf69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# .zshrc
# Craig Jennings <c@cjennings.net>
#
# 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