-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_zshrc
More file actions
200 lines (156 loc) · 6.42 KB
/
_zshrc
File metadata and controls
200 lines (156 loc) · 6.42 KB
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
##
# General
##
setopt PROMPT_SUBST # enable prompt expansions
export CLICOLOR=1
WORDCHARS='_'
##
# History
##
HISTSIZE=10000 # number of histories the shell will keep within one session
SAVEHIST=15000 # the number of lines of history to save
HISTFILE=$HOME/.zhistory
setopt APPEND_HISTORY # append history list to the history file, rather than replace it
setopt HIST_EXPIRE_DUPS_FIRST # drop duplicate histories first when hitting the history size limit
setopt EXTENDED_HISTORY # save each command's beginning timestamp and duration to history
setopt HIST_IGNORE_SPACE
setopt HIST_VERIFY
setopt INC_APPEND_HISTORY # append entries to the history file as soon as they are entered
setopt SHARE_HISTORY
##
# Zinit
##
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"
# # Workaround for zinit issue#504: remove subversion dependency. Function clones all files in plugin
# # directory (on github) that might be useful to zinit snippet directory. Should only be invoked
# # via zinit atclone"_fix-omz-plugin"
# # From: https://github.com/zdharma-continuum/zinit/discussions/651#discussioncomment-11442498
# _fix-omz-plugin() {
# [[ -f ./._zinit/teleid ]] || return 1
# local teleid="$(<./._zinit/teleid)"
# local pluginid
# for pluginid (${teleid#OMZ::plugins/} ${teleid#OMZP::}) {
# [[ $pluginid != $teleid ]] && break
# }
# (($?)) && return 1
# print "Fixing $teleid..."
# git clone --quiet --no-checkout --depth=1 --filter=tree:0 https://github.com/ohmyzsh/ohmyzsh
# cd ./ohmyzsh
# git sparse-checkout set --no-cone /plugins/$pluginid
# git checkout --quiet
# cd ..
# local file
# for file (./ohmyzsh/plugins/$pluginid/*~(.gitignore|*.plugin.zsh)(D)) {
# print "Copying ${file:t}..."
# cp -R $file ./${file:t}
# }
# rm -rf ./ohmyzsh
# }
# This is needed if we source `zinit.zsh` after `compinit`
# autoload -Uz _zinit
# (( ${+_comps} )) && _comps[zinit]=_zinit
##
# Prompt
##
[[ "$SSH_CONNECTION" != '' ]] && PURE_PROMPT_SYMBOL='⋯❯' || PURE_PROMPT_SYMBOL='❯'
zinit ice pick"async.zsh" src"pure.zsh" # with zsh-async library that's bundled with it.
zinit light sindresorhus/pure
zstyle ':prompt:pure:git:dirty' color 242
precmd_functions+=(precmd_postprocessing)
precmd_postprocessing() {
# Hide if using default environments
if [[ $psvar[12] == "base" ]]; then
psvar[12]=
fi
# If $psvar[12] is not blank and starts with current dir, strip it
if [[ -n $psvar[12] ]]; then
if [[ $psvar[12] == /* ]]; then
# Show relative path as it will be shorter in most cases
local rel_path="${psvar[12]#${PWD}/}"
if [[ -n $rel_path && $rel_path != $psvar[12] ]]; then
rel_path="./${rel_path}"
fi
if [[ -n $rel_path ]]; then
psvar[12]="${rel_path}"
fi
fi
fi
}
##
# Plugins
##
# Note: Need to run `zinit delete --clean` to remove old plugins that are no longer used.
# Note: Sometimes even need to run `zinit delete --all` to remove stale completions.
# zinit light mafredri/zsh-async # we are using zsh-async library bundled with the pure theme instead
# Syntax highlighting
zinit ice wait lucid \
atload"FAST_HIGHLIGHT_STYLES[unknown-token]='fg=red'" # do not make the unknown tokens bold (default is bold red)
zinit light zdharma-continuum/fast-syntax-highlighting
# "Auto complete" commands from history
zinit light zsh-users/zsh-autosuggestions
# "Fuzzy" history search when pressing up/down arrow keys
zinit light zsh-users/zsh-history-substring-search
HISTORY_SUBSTRING_SEARCH_FUZZY=true # "ab c" will match "*ab*c*""
HISTORY_SUBSTRING_SEARCH_PREFIXED=true # For example, let `zsh` only match commands starting with `zsh`, not something like `gh completion -s zsh > ~/.zsh/completions/_gh` (`zsh awesome` can still match `zsh my_awesome_script.sh` if HISTORY_SUBSTRING_SEARCH_PREFIXED is enabled)
HISTORY_SUBSTRING_SEARCH_ENSURE_UNIQUE=true # only return unique search results
bindkey '^[[A' history-substring-search-up
bindkey '^[[B' history-substring-search-down
bindkey "$terminfo[kcuu1]" history-substring-search-up
bindkey "$terminfo[kcud1]" history-substring-search-down
# Better Ctrl-R
zinit light zdharma-continuum/history-search-multi-word
# Terminal titles
zinit ice wait lucid
zinit light amyreese/zsh-titles
# Completions
# zinit light conda-incubator/conda-zsh-completion
# Completions from homebrew is broken for `git stash apply`. See: https://github.com/ohmyzsh/ohmyzsh/issues/5754#issuecomment-278968514
# zinit wait lucid atpull"%atclone" atclone"_fix-omz-plugin" for OMZ::plugins/gitfast # We copied gitfast to our `.zsh/utils` directory to patch it
# zinit light zsh-users/zsh-completions
# Other
# zinit light z-shell/zsh-navigation-tools
# zinit light paulirish/git-open
# Abbreviations
# See: https://github.com/olets/zsh-abbr/issues/188
local zsh_abbr_job_queue_dir="${${TMPDIR:-/tmp}%/}/zsh-job-queue/zsh-abbr"
if [[ ! -d $zsh_abbr_job_queue_dir ]]; then
rm -rf "$zsh_abbr_job_queue_dir" &>/dev/null
fi
ABBR_SET_EXPANSION_CURSOR=1
ABBR_DEFAULT_BINDINGS=0 # do not use default bindings
bindkey " " abbr-expand-and-insert
# bindkey "^I" abbr-expand-and-insert # Tab key, do not use this as it will conflict with completions
zi ice ver"v6"
zinit light olets/zsh-abbr
##
# Load Shared Profile
##
# Need to do this before compinit because it may contain `fpath` changes.
if [[ -f "$HOME/.shell_profile" ]]; then
source "$HOME/.shell_profile"
fi
##
# `fpath`
##
# We do this here to let user's `_zsh/functions` and `_zsh/completions` override any other completions.
# Not needed because `eval "$(/opt/homebrew/bin/brew shellenv)"` called in `_shell_profile` will also do this too.
# if type brew &>/dev/null; then
# fpath=("$(brew --prefix)/share/zsh/site-functions" $fpath) # prepend to override zsh built-in completions (such as using /opt/homebrew/share/zsh/site-functions/_git over /usr/share/zsh/5.9/functions/_git)
# fi
if [[ -d $HOME/.zsh/functions ]]; then
fpath=($HOME/.zsh/functions $fpath)
fi
if [[ -d $HOME/.zsh/completions ]]; then
fpath=($HOME/.zsh/completions $fpath)
fi
# Mark every plain file in the functions dir as autoload-able
autoload -Uz ~/.zsh/functions/*(N.:t)
##
# Completions
##
autoload -U compinit && compinit
zstyle ':completion:*' menu select