-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzshrc
147 lines (112 loc) · 4.34 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
# Shell prompt always in the bottom of the screen
tput cup $LINES 0
# Disable annoying flow mode, free up C-S and C-Q
stty -ixon -ixoff
# Check local mail and open it if any
[[ -s $(which mail) ]] && mail -e && mail
# Powerlevel10k instant prompt. Code that may require console input (password prompts, [y/n] etc.)
# must go above this block; everything else may go below.
if [[ -r "$XDG_CACHE_HOME/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "$XDG_CACHE_HOME/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# Prevent overwriting existing files with '> filename', use '>| filename' # (or >!) instead.
# Hat tip http://ruderich.org/simon/config/zshrc
setopt noclobber
# Zsh, please...
unsetopt correct_all
# Credit: https://robots.thoughtbot.com/how-to-use-arguments-in-a-rake-task
# Allow [ or ] whereever you want
unsetopt nomatch
# Ignore duplicate history entries
setopt histignoredups
# Ignore mistyped commands in history https://superuser.com/a/902508/78160
zshaddhistory() { whence ${${(z)1}[1]} >| /dev/null || return 1 }
# Plugins
# # Lazy-load antidote and generate the static load file only when needed
zsh_plugins=${ZDOTDIR:-$HOME}/.zsh_plugins
if [[ ! $zsh_plugins.zsh -nt $zsh_plugins.txt ]]; then
(
source ~/.antidote/antidote.zsh
antidote bundle < $zsh_plugins.txt >! $zsh_plugins.zsh
)
fi
source ${zsh_plugins}.zsh
export ZSH_AUTOSUGGEST_STRATEGY=(history) # (completion history) is too slow
export ZSHZ_DATA=$XDG_CACHE_HOME/z
export ZSHZ_NO_RESOLVE_SYMLINKS=1 # prevent symlink resolution
# Cache completions
autoload -Uz compinit; compinit
# Better vi mode (hat tip Doug Black)
bindkey -v
# Switch to command mode even if in insert mode initially
history-incremental-search-backward-ins () {
zle history-incremental-search-backward
zle -K vicmd
}
zle -N history-incremental-search-backward-ins
bindkey -M viins "^r" history-incremental-search-backward-ins
bindkey -M vicmd "^r" history-incremental-search-backward
# Accept incremental search for further editing with a single escape
bindkey -M isearch '\e' accept-search
bindkey -M isearch kj accept-search
bindkey -M isearch "^p" history-incremental-search-backward
bindkey -M isearch "^n" history-incremental-search-forward
bindkey -M vicmd "H" beginning-of-line
bindkey -M vicmd "L" end-of-line
# Use ff to complete an autosuggestion
bindkey -M viins ff end-of-line
bindkey -M vicmd ff end-of-line
# Better undo/redo
bindkey -M vicmd u undo
bindkey -M vicmd U redo
# Switch to command mode. For me, jk or kk or jj are too slow to type with 0.1s timeout
# kjk<CR> to repeat last command
bindkey -M viins kj vi-cmd-mode
# Yank to the end of line with Y
bindkey -M vicmd Y vi-yank-eol
# Unbind annoying named command binding
bindkey -M vicmd -r ':'
# Switch back to fg %1 on ^Z (hat tip Adam Stankiewicz http://sheerun.net/)
fancy-ctrl-z () {
if [[ $#BUFFER -eq 0 ]]; then
fg
zle redisplay
else
zle push-input
zle clear-screen
fi
}
zle -N fancy-ctrl-z
bindkey -M viins "^Z" fancy-ctrl-z
bindkey -M vicmd "^Z" fancy-ctrl-z
# Edit command in external editor
autoload -U edit-command-line
zle -N edit-command-line
bindkey -M vicmd v edit-command-line
bindkey -M vicmd K run-help
# Color scheme
autoload -U colors && colors
# Aliases
[[ -s ~/.config/zsh/alias.zsh ]] && source ~/.config/zsh/alias.zsh
# Homebrew github api key
[[ -s ~/.config/zsh/brew-api-key.sh ]] && source ~/.config/zsh/brew-api-key.sh
# Google cloud for MacOS via homebrew
# source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc'
# source '/usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc'
# Many programs change the terminal state, and often do not restore terminal settings on exiting abnormally. To avoid the need to manually reset the terminal, freeze it:
ttyctl -f
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# Add JDK for JRuby
export PATH="/usr/local/opt/openjdk/bin:$PATH"
# Use Ruby from Homebrew
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
# Use Python from Homebrew
export PATH="/opt/homebrew/opt/[email protected]/libexec/bin:$PATH"
export HISTSIZE=1000
export SAVEHIST=1000
export HISTFILE=~/.zsh_history
# Machine-specific config
[[ -s ~/.config/zsh/local.zsh ]] && source ~/.config/zsh/local.zsh
# Activate mise-en-place (polyglot version manager and env manager var)
eval "$(mise activate zsh)"