-
Notifications
You must be signed in to change notification settings - Fork 2
/
.zshrc
260 lines (208 loc) · 6.95 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
253
254
255
256
257
258
259
260
# zmodload zsh/zprof
setopt autocd
unsetopt beep
# Home, End, Delete key bindings
bindkey '\e[H' beginning-of-line
bindkey '\e[F' end-of-line
bindkey '\e[3~' delete-char
# Set locales
if [ ! -z "${LANG}" ]; then
export LC_COLLATE=C
export LC_CTYPE="${LANG}"
fi
HISTFILE=~/.histfile
HISTSIZE=10000
SAVEHIST=100000
declare -A colors
colors[bg_0]="#103c48"
colors[bg_1]="#184956"
colors[bg_2]="#2d5b69"
colors[dim_0]="#72898f"
colors[fg_0]="#adbcbc"
colors[fg_1]="#cad8d9"
colors[red]="#fa5750"
colors[green]="#75b938"
colors[yellow]="#dbb32d"
colors[blue]="#4695f7"
colors[magenta]="#f275be"
colors[cyan]="#41c7b9"
colors[orange]="#ed8649"
colors[violet]="#af88eb"
colors[br_red]="#ff665c"
colors[br_green]="#84c747"
colors[br_yellow]="#ebc13d"
colors[br_blue]="#58a3ff"
colors[br_magenta]="#ff84cd"
colors[br_cyan]="#53d6c7"
colors[br_orange]="#fd9456"
colors[br_violet]="#bd96fa"
export colors
# setup Homebrew environment
if [ -z "${HOMEBREW_PREFIX}" ] && [ -x "/usr/local/bin/brew" ] ; then
eval "$(/usr/local/bin/brew shellenv)"
fi
if [ -z "${HOMEBREW_PREFIX}" ] && [ -x "/home/linuxbrew/.linuxbrew/bin/brew" ] ; then
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
fi
if [ -n "${HOMEBREW_PREFIX}" ]; then
FPATH="${HOMEBREW_PREFIX}/share/zsh-completions:${FPATH}"
fi
# Add development tools to PATH
if [ -d "${HOMEBREW_PREFIX}/opt/node@20/bin" ] ; then
export PATH="${HOMEBREW_PREFIX}/opt/node@20/bin:${PATH}"
fi
if [ -d "${HOMEBREW_PREFIX}/opt/python@3.12/bin" ] ; then
export PATH="${HOMEBREW_PREFIX}/opt/python@3.12/bin:${PATH}"
fi
if [ -d "${HOMEBREW_PREFIX}/opt/go@1.21/bin" ] ; then
export PATH="${HOMEBREW_PREFIX}/opt/go@1.21/bin:${PATH}"
fi
if [ -d "${HOMEBREW_PREFIX}/opt/php@8.1/bin" ] ; then
export PATH="${HOMEBREW_PREFIX}/opt/php@8.1/bin:${PATH}"
fi
FPATH="${HOME}/.zfunc:${FPATH}"
autoload -Uz compinit && compinit
autoload -U +X bashcompinit && bashcompinit
# Load version control information
autoload -Uz vcs_info
autoload -U add-zsh-hook
# check for changes
zstyle ':vcs_info:*' check-for-changes true
# Format the vcs_info_msg_0_ variable
zstyle ':vcs_info:*:*' stagedstr '+'
zstyle ':vcs_info:*:*' unstagedstr '*'
zstyle ':vcs_info:*:*' formats ' (%b)%u%c'
zstyle ':vcs_info:*:*' actionformats ' (%b|%a)%u%c'
zstyle ':vcs_info:*:*' nvcsformats ''
### git: Show unstagedstr marker (*) if there are untracked files in repository
# Make sure you have added unstaged to your 'formats': %u
zstyle ':vcs_info:git*+set-message:*' hooks git-untracked
+vi-git-untracked() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
git status --porcelain | grep -q '^?? ' 2> /dev/null ; then
hook_com[unstaged]='*'
fi
}
if [[ -n "${HOMEBREW_PREFIX}" ]] && [[ -f "${HOMEBREW_PREFIX}/opt/kube-ps1/share/kube-ps1.sh" ]]; then
source "${HOMEBREW_PREFIX}/opt/kube-ps1/share/kube-ps1.sh"
fi
_set_prompt() {
vcs_info
local venv=""
if [[ -n "${VIRTUAL_ENV}" ]] ; then
if [[ -n "${VIRTUAL_ENV_PROMPT}" ]] ; then
venv="${VIRTUAL_ENV_PROMPT}"
elif [[ "${VIRTUAL_ENV##*/}" == ".venv" ]] ; then
venv="(${$(dirname "$VIRTUAL_ENV")##*/}) "
else
venv="(${VIRTUAL_ENV##*/}) "
fi
fi
host_prompt=""
if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
host_prompt="%K{${colors[bg_1]}}%F{${colors[dim_0]}} %n@%m %f%k "
fi
PS1="%F{3}λ%f ${host_prompt}${venv}%~${vcs_info_msg_0_} ❯ "
PS2=" ❯ "
RPROMPT=""
if [[ "off" != "${KUBE_PS1_ENABLED}" ]]; then
test -n "${KUBE_PS1_CONTEXT}" && RPROMPT="${KUBE_PS1_CONTEXT}"
test -n "${KUBE_PS1_NAMESPACE}" && RPROMPT="${RPROMPT}:${KUBE_PS1_NAMESPACE}"
fi
test -n "${RPROMPT}" && RPROMPT="%K{${colors[bg_1]}}%F{${colors[dim_0]}} ${RPROMPT} %f%k"
}
function git() {
if [ "${PWD}" = "${HOME}" ] || [ "${PWD}" = "${HOME}/.config" ] || [ "${PWD}" = "${HOME}/.local" ]; then
GIT_DIR="${HOME}/.dotfiles.git" \
GIT_WORK_TREE="${HOME}" \
command git "$@"
else
command git "$@"
fi
}
add-zsh-hook precmd _set_prompt
if [[ -n "${HOMEBREW_PREFIX}" ]] && [[ -x "${HOMEBREW_PREFIX}/bin/gls" ]]; then
alias ls="${HOMEBREW_PREFIX}/bin/gls"
fi
DIRCOLORS=/usr/bin/dircolors
if [[ -n "${HOMEBREW_PREFIX}" ]] && [[ -x "${HOMEBREW_PREFIX}/bin/gdircolors" ]]; then
DIRCOLORS="${HOMEBREW_PREFIX}/bin/gdircolors"
alias dircolors="${DIRCOLORS}"
fi
if [[ -x "${DIRCOLORS}" ]]; then
test -r "${HOME}/.dircolors" && eval "$("${DIRCOLORS}" -b "${HOME}/.dircolors")" || eval "$($DIRCOLORS -b)"
if [[ -n "${HOMEBREW_PREFIX}" ]] && [[ -x "${HOMEBREW_PREFIX}/bin/gls" ]]; then
alias ls="${HOMEBREW_PREFIX}/bin/gls --color=auto"
else
alias ls='ls --color=auto'
fi
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
fi
if [[ -d "${HOME}/.composer/vendor/bin" ]] ; then
export PATH="${HOME}/.composer/vendor/bin:$PATH"
fi
export GOPATH="$HOME/work"
export PATH="$GOPATH/bin:$PATH"
if [[ -d "${HOME}/.local/bin" ]] ; then
export PATH="${HOME}/.local/bin:$PATH"
fi
export EDITOR=vim
if [ -f /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc ] ; then
source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/completion.zsh.inc
fi
if [ -f /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc ] ; then
source /usr/local/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/path.zsh.inc
fi
# lazy load kubectl completion
if [ $commands[kubectl] ]; then
kubectl() {
unfunction "$0"
source <(kubectl completion zsh)
$0 "$@"
}
fi
# lazy load azure-cli completion
if [ $commands[az] ]; then
az() {
unfunction "$0"
test -f "${HOMEBREW_PREFIX}/etc/bash_completion.d/az" && source "${HOMEBREW_PREFIX}/etc/bash_completion.d/az"
$0 "$@"
}
fi
FZF_PREVIEW_OPTS="cat {}"
if [ $commands[rich] ]; then
FZF_PREVIEW_OPTS="rich --force-terminal -n -y --max-width=\$FZF_PREVIEW_COLUMNS {}"
fi
FZF_DEFAULT_OPTS=$(cat <<-EOD
--color="fg:${colors[fg_0]},bg:${colors[bg_0]},hl:${colors[cyan]}:bold"
--color="fg+:${colors[fg_0]}:regular,bg+:${colors[bg_1]},hl+:$colors[br_cyan]:bold"
--color="pointer:${colors[cyan]},prompt:${colors[yellow]}:bold"
--color="info:${colors[blue]}"
--color="query:${colors[fg_0]}:regular"
--color="border:${colors[bg_2]}"
--color="header:${colors[fg_1]}:bold,label:${colors[fg_1]}:bold"
--preview-window=border-bold
--scrollbar='▐'
--separator='━'
--prompt='❯ '
--pointer='❯'
EOD
)
export FZF_DEFAULT_OPTS
__envchain_namespaces() {
_values 'namespace' "${(uonzf)$(envchain --list)}"
}
_envchain() {
_arguments -S -A '-*' \
':namespace:__envchain_namespaces' \
':command: _command_names -e' \
'*::arguments:_precommand'
}
compdef _envchain envchain
export PATH="${HOME}/bin:$PATH"
source ~/.aliases
if [[ -f "${HOME}/.zshrc.local" ]] ; then
source "${HOME}/.zshrc.local"
fi