/
.zshrc
315 lines (242 loc) · 7.57 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# Created by newuser for 5.8
# Contents are listed in following order:
# Modules
# Options
# Shell Variables
# Hook Functions
# Functions
# Completions
# Key bindings
# Highlightings
# Aliases
# Variables
## Modules
zmodload zsh/pcre
zmodload zsh/complist
## Options ##
setopt append_create
unsetopt clobber
setopt correct
unsetopt correct_all
setopt extended_glob
setopt extended_history
setopt hist_ignore_space
setopt hist_verify
setopt interactive_comments
setopt magic_equal_subst
setopt no_auto_menu
setopt prompt_subst
setopt re_match_pcre
## Shell Variables ##
export HISTFILE=${ZDOTDIR:-$HOME}/.zhistory
export HISTSIZE=100000
export PROMPT_EOL_MARK='%B%S%#%s%b'
export SAVEHIST=100000
export SPROMPT="zsh: correct '%B%R%b' to '%B%r%b' ([n]/y/a/e)? %B"
export WORDCHARS=''
export fignore=(.o '~')
# export fpath=(
# ~/.zsh/completions
# ~/git/rsk0315/configurations/.zsh/functions
# ~/.zsh/functions
# $fpath
# )
# https://github.com/zsh-users/zsh/blob/96a79938010073d14bd9db31924f7646968d2f4a/Completion/Unix/Command/_git
# Put it in ~/.zsh/completions/
### Prompt String ###
# See https://unix.stackexchange.com/questions/40595/
autoload -U smart-exit-status
PS1='%f'
PS1+=$'%(1v_$(smart-exit-status $?)\n_)' # exit status
PS1+=$'\n%f'
PS1+="$ZSH_PATCHLEVEL [%L]" # shell information
PS1+="%(1j. (%j job%(2j s )%).)" # jobs
PS1+=' %F{238}%D{%Y-%m-%d %H:%M:%S}' # time
PS1+=$'\n'
PS1+='%F{45}%~/%f' # current directory
PS1+='$(__git_ps1 " %%F{168}(on %s)%%f")' # git branch
PS1+=$'\n'
if [[ $(print -P %m) =~ ^[0-9a-f]*$ ]]; then
PS1+='%F{244}%m%f'
fi
PS1+='%# ' # prompt character
### Paths ###
# path=(... $path)
# manpath=(... $manpath)
typeset -U path manpath fpath
## Hook Functions ##
state='standby'
precmd() {
unset unseen
if [[ "$state" == 'executing' ]]; then
state='executed'
psvar=(1)
else
state='standby'
psvar=()
fi
stty intr undef # ^c
stty-undef
}
preexec() {
# print -R "\$1: '$1'"
# print -R "\$2: '$2'"
# print -R "\$3: '$3'"
print -Pn '%f%k%b%s%u'
ts='%F{238}# %D{%Y-%m-%d %H:%M:%S}%f'
# `if>` や `for>` のプロンプトの有無の判定が不可能なので、複数行のときは諦める。
# PS1 の最後の行の文字数の問題もあるが、`%# ` で決め打ちにしちゃう。
# あーでも他もろもろの理由で変になることはあるかなあ。
# `%m%# ` のときうれしくなさそう。
lastlen=$(( ${#1##*$'\n'} % COLUMNS ))
host=$(print -P %m)
if [[ $host =~ ^[0-9a-f]*$ ]]; then
((lastlen += $#host))
fi
if [[ "$1" =~ '\n' ]] || ((lastlen >= COLUMNS - 23)); then
print -P "${(l:COLUMNS-21:)}$ts"
else
csi=$'\x1b['
print -P "${csi}1A${csi}${COLUMNS}C${csi}20D${ts}"
fi
state='executing'
stty intr '^c'
stty-undef
}
update_terminal_cwd() {
# See /etc/zshrc_Apple_Terminal
local url_path=''
{
local i ch hexch LC_CTYPE=C LC_COLLATE=C LC_ALL= LANG=
for ((i = 1; i <= ${#PWD}; ++i)); do
ch="$PWD[i]"
# suppress error messages like
# > update_terminal_cwd:13: pcre_exec() error [-10]
# which appears when $PWD contains non-ASCII characters.
if [[ "$ch" =~ [/._~A-Za-z0-9-] ]] 2> /dev/null; then
url_path+="$ch"
else
printf -v hexch "%02X" "'$ch"
url_path+="%$hexch"
fi
done
}
printf '\e]7;%s\a' "file://$HOST$url_path"
}
TRAPINT() {
if [[ "$state" != 'executing' ]]; then
print -P '%B%S^C%s%b'
fi
return $((128+$1))
}
## Functions ##
autoload -U visualize-characters
. ~/.zsh/git-prompt.sh
## Completions ##
zstyle ':completion:*' show-ambiguity '1;32'
zstyle ':completion:*' matcher-list 'r:|[._-]=** r:|/=* r:|=* r:|[[:upper:]]=*'
autoload -Uz compinit
compinit
## Key Bindings ##
stty-undef() {
stty start undef # ^q
stty rprnt undef # ^r
stty stop undef # ^s
stty kill undef # ^u
stty werase undef # ^w
}
stty-undef
bindkey -e
bindkey '^[#' pound-insert
bindkey '^[f' emacs-forward-word
bindkey '^U' universal-argument
bindkey '^W' kill-region
# bindkey '^I' expand-or-complete-prefix
autoload -U numeric-argument
zle -N numeric-argument && bindkey '^U' numeric-argument
# autoload -U send-invisible
# zle -N send-invisible && bindkey '^X ' send-invisible
autoload -U send-unseen
zle -N send-unseen && bindkey '^X ' send-unseen
autoload -U zletest
zle -N zletest && bindkey '^X^Z' zletest
autoload -U interrupt-line
zle -N interrupt-line && bindkey '^C' interrupt-line
autoload -U abort
zle -N abort && bindkey '^G' abort '^[^G' abort
bindkey -M isearch '^G' send-break '^[^G' send-break
bindkey -M isearch '^C' send-break
bindkey -r '^H' '^X^R'
autoload -U describe-key
zle -N describe-key && bindkey '^Hk' describe-key
autoload -U describe-variable
zle -N describe-variable && bindkey '^Hv' describe-variable
autoload -U input-function-name && zle -N input-function-name
autoload -U describe-function
zle -N describe-function && bindkey '^Hf' describe-function
autoload -U delete-horizontal-space
zle -N delete-horizontal-space && bindkey '^[\' delete-horizontal-space
autoload -U just-one-space
zle -N just-one-space && bindkey '^[ ' just-one-space
autoload -U find-file
zle -N find-file && bindkey '^X^F' find-file
autoload -U find-file-read-only
zle -N find-file-read-only && bindkey '^X^R' find-file-read-only
autoload -U zap-to-char
zle -N zap-to-char && bindkey '^[z' zap-to-char
autoload -U color-picker
zle -N color-picker && bindkey '^Xc' color-picker
autoload -U cut-to-pasteboard
zle -N cut-to-pasteboard && bindkey '^X^W' cut-to-pasteboard
autoload -U copy-to-pasteboard
zle -N copy-to-pasteboard && bindkey '^X^[w' copy-to-pasteboard
autoload -U paste-from-pasteboard
zle -N paste-from-pasteboard && bindkey '^X^Y' paste-from-pasteboard
autoload -U select-current-word
zle -N select-current-word && bindkey '^Xw' select-current-word
autoload -U toggle-case
zle -N toggle-case && bindkey '^Xt' toggle-case
autoload -U toggle-case-word
zle -N toggle-case-word && bindkey '^XT' toggle-case-word
## Highlightings ##
zmodload zsh/nearcolor
zle_highlight=(special:fg=9,bold)
source $HOME/git/zsh-users/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source $HOME/.zhighlight
## Aliases ##
alias cp='cp -iv'
alias rm='rm -iv'
alias mv='mv -iv'
alias d='dirs -v'
alias j='jobs'
alias man='MANWIDTH=$((COLUMNS-10)) man -P "bat --wrap never"'
alias ll='exa -l --sort=Name --time-style=long-iso'
alias lll='exa -l --sort=Name --time-style=long-iso --tree'
alias delta='delta --paging never'
alias fd='fd -HI'
alias rg='rg -. --no-ignore'
alias scriptq='script -q -- /dev/null'
alias cb='cargo build'
alias cbr='cargo build --release'
alias cbc='RUSTFLAGS="-C instrument-coverage" cargo build'
alias cr='cargo run'
alias crr='cargo run --release'
alias crc='RUSTFLAGS="-C instrument-coverage" cargo run'
alias ct='cargo test'
alias ctr='cargo test --release'
## Variables ##
export LESS_TERMCAP_mb=$'\e[1;31m'
export LESS_TERMCAP_md=$'\e[1;38;5;74m'
export LESS_TERMCAP_me=$'\e[m'
export LESS_TERMCAP_se=$'\e[m'
# export LESS_TERMCAP_so=$'\e[38;5;246m'
unset LESS_TERMCAP_so
export LESS_TERMCAP_ue=$'\e[m'
export LESS_TERMCAP_us=$'\e[4;38;5;146m'
export LESS=-NR
export BAT_PAGER='less -Rn'
export BAT_THEME='Monokai Extended'
export EXA_COLORS='uu=38;5;10:un=38;5;9:da=38;5;140:ur=1;37:gr=38;5;15:tr=38;5;15:gw=38;5;9:tw=38;5;9:gx=38;5;10:tx=38;5;10:di=1;38;5;68:cc=1;31:ln=1;38;5;213:xx=37:ga=38;5;10:gm=38;5;10:gd=38;5;9:xa=38;5;13'
export LLVM_PROFILE_FILE='%m-%p.profraw'
export PYTHONSTARTUP=$HOME/.pythonrc.py
# export CXX=g++-11