-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
.zshrc
181 lines (139 loc) · 5.96 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
# =============
# Completion
# =============
# forces zsh to realize new commands
zstyle ':completion:*' completer _oldlist _expand _complete _match _ignored _approximate
# matches case insensitive for lowercase
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# pasting with tabs doesn't perform completion
zstyle ':completion:*' insert-tab pending
# rehash if command not found (possibly recently installed)
zstyle ':completion:*' rehash true
# speed https://coderwall.com/p/9fksra/speed-up-your-zsh-completions
zstyle ':completion:*' accept-exact '*(N)'
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
# force completion generation for more obscure commands
# TODO unsure if vitest + eslint will really work here automatically given it's installed via pnpm
# TODO look at mise usage tool here, could be a bit better
zstyle :plugin:zsh-completion-generator programs ncdu tre vitest eslint fastmod ipython fzf
# =============
# fzf-tab config
# =============
# set descriptions format to enable group support
zstyle ':completion:*:descriptions' format '[%d]'
# set list-colors to enable filename colorizing
zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# preview directory's content with exa when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
# switch group using `,` and `.`
zstyle ':fzf-tab:*' switch-group ',' '.'
# menu if nb items > 2
zstyle ':completion:*' menu select=2
# preview directory's content with exa when completing cd
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --color=always $realpath'
# don't show fzf unless there are more than 4 items
# zstyle ':fzf-tab:*' ignore false 4
# =============
# Shell Options
# man: zshoptions
# =============
setopt interactive_comments
setopt prompt_subst
setopt extended_glob # Allow extended matchers like ^file, etc
setopt long_list_jobs
setopt auto_cd
setopt menu_complete # Auto pick a menu match
# Set history behavior
setopt share_history # Share history across session
setopt inc_append_history # Dont overwrite history, add new entries immediately
setopt extended_history # Also record time and duration of commands.
setopt hist_expire_dups_first # Clear duplicates when trimming internal hist.
setopt hist_find_no_dups # Dont display duplicates during searches.
setopt hist_ignore_dups # Ignore consecutive duplicates.
setopt hist_reduce_blanks # Remove superfluous blanks.
setopt hist_save_no_dups # Omit older commands in favor of newer ones.
# Evals
# =============
# we tried linux homebrew, but it's terrible :/
brew_path="/opt/homebrew/bin/brew"
if [[ -x "$brew_path" ]]; then
eval "$($brew_path shellenv)"
fi
# postgres utilities
export PATH="/Applications/Postgres.app/Contents/Versions/15/bin:$PATH"
# poetry, orb, etc
export PATH="$HOME/.local/bin:$PATH"
# for latest gnu make
export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"
# TODO I don't understand where this comes from, but it seems to be used by some completion libraries
fpath+=~/.zfunc
# avoid installation via brew, this is not a supported installation method and breaks
# some directory structure assumptions that exist across the plugin ecosystem.
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
[ ! -d $ZINIT_HOME ] && mkdir -p "$(dirname $ZINIT_HOME)"
[ ! -d $ZINIT_HOME/.git ] && git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
source "${ZINIT_HOME}/zinit.zsh"
# TODO https://github.com/zdharma/zinit/issues/173#issuecomment-537325714
# Load ~/.exports, ~/.aliases, ~/.functions and ~/.extra
# ~/.extra can be used for settings you don’t want to commit
for file in exports aliases functions extra; do
file="$HOME/.$file"
[ -e "$file" ] && source "$file"
done
source ~/.zsh_plugins
# ===========
# Keybindings
# ===========
bindkey "^[[A" history-substring-search-up # Up
bindkey "^[[B" history-substring-search-down # Down
# match vscode's ^k functionality
bindkey "^K" kill-line
# cmd+shift+k is not possible in the terminal without remapping cmd, which is not a good idea given it's lack of support
# opt+shift+k deletes backward, ctrl+U defaults to kill-whole-line
bindkey "^[K" backward-kill-line
# open up current command in EDITOR, ctrl+x then ctrl+e
autoload -U edit-command-line
zle -N edit-command-line
bindkey '^X^E' edit-command-line
# save current command in buffer & restore after next command is run
# https://unix.stackexchange.com/a/74381
autoload -U push-input
# not sure why, but ^S is not getting passed to the terminal
bindkey '^X^P' push-input
# ===========
# Misc Config
# ===========
# https://til.hashrocket.com/posts/7evpdebn7g-remove-duplicates-in-zsh-path
typeset -aU path
# https://github.com/ohmyzsh/ohmyzsh/blob/master/lib/misc.zsh
autoload -Uz url-quote-magic
zle -N self-insert url-quote-magic
# stop autosuggesting after ^w or ^k is pressed
ZSH_AUTOSUGGEST_IGNORE_WIDGETS+=(backward-kill-word kill-line)
# =======================================
# zsh-autosuggest & bracketed-paste-magic
# =======================================
# copied from https://github.com/zsh-users/zsh-autosuggestions/issues/351#issuecomment-588235793
# hopefully this is fixed in zsh-autosuggest in the future
# This speeds up pasting w/ autosuggest
# https://github.com/zsh-users/zsh-autosuggestions/issues/238
pasteinit() {
OLD_SELF_INSERT=${${(s.:.)widgets[self-insert]}[2,3]}
zle -N self-insert url-quote-magic # I wonder if you'd need `.url-quote-magic`?
}
pastefinish() {
zle -N self-insert $OLD_SELF_INSERT
}
zstyle :bracketed-paste-magic paste-init pasteinit
zstyle :bracketed-paste-magic paste-finish pastefinish
# https://github.com/zsh-users/zsh-autosuggestions/issues/351
ZSH_AUTOSUGGEST_CLEAR_WIDGETS+=(bracketed-paste)
# ===========
# Word Definition
# ===========
# http://mikebian.co/fixing-word-navigation-in-zsh/
WORDCHARS='*?_-.[]~=&;!#$%^(){}<>/ '$'\n'
autoload -Uz select-word-style
select-word-style normal
zstyle ':zle:*' word-style unspecified