-
Notifications
You must be signed in to change notification settings - Fork 0
/
.zshrc
216 lines (156 loc) · 5 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
HISTFILE=~/.zhistory
HISTSIZE=10000
SAVEHIST=10000
declare opts=(
inc_append_history
hist_fcntl_lock
hist_save_no_dups
hist_expire_dups_first
hist_ignore_all_dups
hist_ignore_dups
hist_find_no_dups
hist_ignore_space
hist_no_functions
hist_no_store
hist_reduce_blanks
hist_verify
cd_silent
pushd_silent
always_to_end
complete_in_word
no_list_beep
correct
correct_all
# glob_dots
# numeric_glob_sort
# magic_equal_subst
interactive_comments
)
setopt $opts
zstyle ':completion:*' menu select
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zcompcache
declare -A plugins=(
[brew]=/opt/homebrew/share/zsh/site-functions
[gitstatus]=/opt/homebrew/opt/gitstatus/gitstatus.plugin.zsh
[orbstack]=/Applications/OrbStack.app/Contents/Resources/completions/zsh
)
if [[ -d $plugins[brew] ]]; then
fpath=( $plugins[brew] $fpath )
fi
if [[ -f $plugins[gitstatus] ]]; then
source $plugins[gitstatus]
fi
if [[ -d $plugins[orbstack] ]]; then
fpath=( $plugins[orbstack] $fpath )
fi
if [[ ! -e ~/.zcomet || -d ~/.zcomet ]]; then
if [[ ! -e ~/.zcomet ]]; then
git clone https://github.com/agkozak/zcomet.git ~/.zcomet/bin
fi
if [[ -e ~/.zcomet/bin/zcomet.zsh ]] && source ~/.zcomet/bin/zcomet.zsh; then
zcomet fpath zsh-users/zsh-completions src
zcomet load zdharma-continuum/fast-syntax-highlighting
zcomet load hlissner/zsh-autopair
zstyle ':zcomet:compinit' dump-file ~/.zcompdump
zcomet compinit
fi
fi
if ! functions zcomet &>/dev/null; then
autoload -U compinit && compinit
fi
declare -A ps
if [[ $USER != ffuugoo && $USER != root ]]; then
ps[user]=%n
fi
if [[ -v SSH_CLIENT ]]; then
ps[host]=%m
fi
ps[at]=${ps[user]:+${ps[host]:+@}}
ps[user-host-sep]=${${ps[user]:+ }:-${ps[host]:+ }}
ps[user-host]=${ps[user]}${ps[at]}${ps[host]}${ps[user-host-sep]}
ps[prompt]='%(?:%F{blue}:%F{red})%B%#%f%b '
ps[status]='%(?::%F{red}%B(%?%)%f%b )'
ps[pwd]='%50<...<%~%<<'
if functions gitstatus_query &>/dev/null; then
declare -A psid
function psid { [[ $# -eq 1 && -n $1 ]] && psvar+=( '' ) && psid[$1]=${#psvar} }
psid git-ref
psid git-mods
ps[git-ref]="%25>...>%${psid[git-ref]}v%>>"
ps[git-mods]="%(${psid[git-mods]}V.%${psid[git-mods]}v.)"
ps[git-status]="%(${psid[git-ref]}V. %F{black}${ps[git-ref]}${ps[git-mods]}%f.)"
autoload -Uz add-zsh-hook && add-zsh-hook precmd gitstatus-precmd
declare GITSTATUS_PWD=$PWD
declare GITSTATUS_ASYNC=0
function gitstatus-precmd {
(( $GITSTATUS_ASYNC )) && return 0
gitstatus-query || return $?
gitstatus-result
}
function gitstatus-query {
psvar[${psid[git-ref]}]=''
psvar[${psid[git-mods]}]=''
GITSTATUS_PWD=$PWD
gitstatus_check GITSTATUS || gitstatus_start -t 1.0 GITSTATUS || return $?
gitstatus_query -t 0.1 -c gitstatus-async GITSTATUS || return $?
}
function gitstatus-async {
GITSTATUS_ASYNC=0
[[ $GITSTATUS_PWD == $PWD ]] || gitstatus-query || return $?
gitstatus-result
[[ $VCS_STATUS_RESULT != tout ]] && zle && zle reset-prompt
}
function gitstatus-result {
case $VCS_STATUS_RESULT in
ok-*)
psvar[${psid[git-ref]}]=${VCS_STATUS_LOCAL_BRANCH:-${VCS_STATUS_TAG:-${VCS_STATUS_COMMIT[1,7]}}}
(( VCS_STATUS_HAS_UNSTAGED )) && psvar[${psid[git-mods]}]=*
;;
tout)
GITSTATUS_ASYNC=1
;;
esac
}
fi
declare PS1=${ps[user-host]}${ps[prompt]}
declare RPS1=${ps[status]}${ps[pwd]}${ps[git-status]}
declare -A key
function key { [[ $# -eq 2 && -n $1 && -n $2 && -v terminfo[$2] ]] && key[$1]=$terminfo[$2] }
function bind { [[ $# -eq 2 && -n $1 && -n $2 && -v key[$1] ]] && bindkey -- $key[$1] $2 }
key Backspace kbs
key Delete kdch1
key Up kcuu1
key Down kcud1
key Left kcub1
key Right kcuf1
key Alt-Up kUP3
key Alt-Down kDN3
key Alt-Left kLFT3
key Alt-Right kRIT3
key Home khome
key End kend
key PageUp kpp
key PageDown knp
key Shift-Tab kcbt
bind Backspace backward-delete-char
bind Delete delete-char
bind Up up-line-or-history
bind Down down-line-or-history
bind Left backward-char
bind Right forward-char
bind Alt-Up history-beginning-search-backward
bind Alt-Down history-beginning-search-forward
bind Alt-Left backward-word
bind Alt-Right forward-word
bind Home beginning-of-line
bind End end-of-line
bind PageUp beginning-of-buffer-or-history
bind PageDown end-of-buffer-or-history
bind Shift-Tab reverse-menu-complete
if [[ -v terminfo[smkx] && -v terminfo[rmkx] ]]; then
function zle-line-init { echoti smkx } && zle -N zle-line-init
function zle-line-finish { echoti rmkx } && zle -N zle-line-finish
fi
alias less="less -FR"
alias ls="ls --color=auto"