-
Notifications
You must be signed in to change notification settings - Fork 17
/
zshrc
252 lines (196 loc) · 6.64 KB
/
zshrc
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# My zsh configuration is designed to be as lean as possible while still giving
# me all the features I need, like autocomplete and git integration.
#
# Commands helpful when building zsh config
#
# * bindkey -l - List all keymaps available
# * bindkey -M <keymap> - Show all bindings in a keymap
# * setopt - show zsh options that are set
# * zstyle - show configured styles
#
# Helpful widgets
#
# * where-is - show what keystrokes a particular widget is bound to
# * describe-key-briefly - show escape sequence for keystroke
#
# References
#
# * https://ohmyz.sh/
# * https://thevaluable.dev/zsh-install-configure-mouseless/
# * https://thevaluable.dev/zsh-line-editor-configuration-mouseless/
# * https://zsh.sourceforge.io/Doc/Release/Zsh-Line-Editor.html#Standard-Widgets
# * https://zsh.sourceforge.io/Doc/Release/Options.html#Option-Aliases
# * https://thevaluable.dev/zsh-completion-guide-examples/
# * https://github.com/Phantas0s/.dotfiles/blob/master/zsh/zshrc
# GENERAL
# ----------
# We need this so that tmux uses zsh when started in a zsh shell
export SHELL='/bin/zsh'
# Print jobs in long format
setopt LONG_LIST_JOBS
# Allow comments in interactive shells
setopt INTERACTIVE_COMMENTS
# Enable implicit redirection to multiple streams: echo >file1 >file2
setopt MULTIOS
# NAVIGATION
# ----------
# Navigate to directory by name without using cd
setopt AUTO_CD
# Automatically push directories to the stack when cd'ing
setopt AUTO_PUSHD
# Don't store duplicates on the stack
setopt PUSHD_IGNORE_DUPS
# Swap the meaning of cd +1 and cd -1
setopt PUSHD_MINUS
# Don't print the directory stack when pushing or popping
setopt PUSHD_SILENT
# COMPLETION
# ----------
# Not sure if I want to keep these settings
setopt ALWAYS_TO_END
setopt COMBINING_CHARS
# Complete from both ends of a word
setopt COMPLETE_IN_WORD
# This is faster than `autoload -U compinit && compinit`
autoload -Uz compinit
zcompdump_current() {
if [[ $(uname -s) == 'Darwin' ]]; then
[ "$(date +'%s')" != "$(stat -f '%Y' -t '%j' $HOME/.zcompdump)" ];
else
[ "$(date +'%s')" != "$(stat -c '%Y' $HOME/.zcompdump)" ];
fi
}
if zcompdump_current; then
compinit
else
compinit -C
fi
# Load antigen
source $HOME/.antigen/antigen.zsh
# zsh syntax highlighting
antigen bundle zsh-users/zsh-syntax-highlighting
# Tell Antigen that you're done.
antigen apply
# Use asdf autocompletions
. $HOME/.asdf/completions/_asdf
# HISTORY
# ----------
# Default location for history file
HISTFILE=$HOME/.zsh_history
# There is no way to define history size as infinite so we set it to 1 billion
HISTSIZE=999999999
SAVEHIST=$HISTSIZE
# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# The optional three formats: "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# HIST_STAMPS="mm/dd/yyyy"
# Prefer unique commands in history
# If the internal history needs to be trimmed to add the current command line,
# setting this option will cause the oldest history event that has a duplicate
# to be lost before losing a unique event from the list.
setopt HIST_EXPIRE_DUPS_FIRST
# Do not enter command lines into the history list if they are duplicates of the previous event.
setopt HIST_IGNORE_DUPS
# Don't save commands to history when they start with a space, or when the alias
# contains a leading space
setopt HIST_IGNORE_SPACE
# Not totally sure I need this
setopt HIST_VERIFY
# Incrementally write history to file
setopt INC_APPEND_HISTORY
# Save timestamp to history file too
setopt EXTENDED_HISTORY
# TODO: I need to either disable SHARE_HISTORY or INC_APPEND_HISTORY
# Import newly written commands from the history file
setopt SHARE_HISTORY
# Do not write duplicate event to history file
setopt HIST_SAVE_NO_DUPS
precmd() {
if [ "$(id -u)" -ne 0 ]; then
echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history | tail -n 1)" >>! $HOME/history/zsh-history-$(date "+%Y-%m-%d").log;
fi
}
# KEY BINDINGS
# ----------
# Use vi mode
bindkey -v
# Make Vi mode transitions faster (KEYTIMEOUT is in hundredths of a second)
export KEYTIMEOUT=1
# Vi mode settings
# Better searching in command mode
bindkey -M vicmd '?' history-incremental-search-backward
bindkey -M vicmd '/' history-incremental-search-forward
# Beginning search with arrow keys in insert mode or k/j command mode
autoload -U up-line-or-beginning-search
autoload -U down-line-or-beginning-search
zle -N up-line-or-beginning-search
zle -N down-line-or-beginning-search
bindkey "^[[A" up-line-or-beginning-search
bindkey "^[[B" down-line-or-beginning-search
bindkey -M vicmd "k" up-line-or-beginning-search
bindkey -M vicmd "j" down-line-or-beginning-search
# Maintain traditional incremental search behavior
bindkey '^r' history-incremental-search-backward
# Vi-mode text object bindings
autoload -Uz select-bracketed select-quoted
zle -N select-quoted
zle -N select-bracketed
for km in viopp visual; do
bindkey -M $km -- '-' vi-up-line-or-history
for c in {a,i}${(s..)^:-\'\"\`\|,./:;=+@}; do
bindkey -M $km $c select-quoted
done
for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
bindkey -M $km $c select-bracketed
done
done
# Easier, more vim-like editor opening
# `v` is already mapped to visual mode, so we need to use a different key to
# open Vim
autoload -Uz edit-command-line
zle -N edit-command-line
bindkey -M vicmd "^V" edit-command-line
# Yank to the system clipboard
function vi-yank-xclip {
zle vi-yank
echo "$CUTBUFFER" | pbcopy -i
}
zle -N vi-yank-xclip
bindkey -M vicmd 'y' vi-yank-xclip
# decarg isn't going to work until the next version of Zsh is tagged (current
# is 5.9.0) but I'm adding it now because I think this will be something I will
# use.
# https://github.com/zsh-users/zsh/blob/master/Functions/Zle/incarg
autoload -Uz incarg
for widget in vim-{,sync-}{inc,dec}arg; do
zle -N "$widget" incarg
done
bindkey -a \
'^A' vim-incarg \
'^X' vim-decarg \
'g^A' vim-sync-incarg \
'g^X' vim-sync-decarg
# THEME & GIT
# ----------
DOTFILES_DIR=$HOME/dotfiles
# Theme uses git functions
source $DOTFILES_DIR/zsh/git.zsh
# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
DISABLE_UNTRACKED_FILES_DIRTY="true"
# Load theme
source $HOME/dotfiles/zsh/theme.zsh
# SCRIPTS & CUSTOM
# ----------
source $DOTFILES_DIR/mixins/general
source $DOTFILES_DIR/mixins/functions
source $DOTFILES_DIR/mixins/grep
source $DOTFILES_DIR/mixins/path
source $DOTFILES_DIR/mixins/asdf
source $DOTFILES_DIR/mixins/aliases
source $DOTFILES_DIR/mixins/man_color
# Custom options
if [ -f "$HOME/dotfiles/mixins/shellrc.custom" ]; then
source "$HOME/dotfiles/mixins/shellrc.custom"
fi