-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot_zshrc.tmpl
257 lines (215 loc) · 6.5 KB
/
dot_zshrc.tmpl
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
# xdg
[[ -z "$XDG_CONFIG_HOME" ]] && export XDG_CONFIG_HOME="$HOME/.config"
[[ -z "$XDG_CACHE_HOME" ]] && export XDG_CACHE_HOME="$HOME/.cache"
[[ -z "$XDG_DATA_HOME" ]] && export XDG_DATA_HOME="$HOME/.local/share"
[[ -z "$XDG_STATE_HOME" ]] && export XDG_STATE_HOME="$HOME/.local/state"
# zinit
if [[ ! -f $XDG_DATA_HOME/zinit/zinit.git/zinit.zsh ]]; then
print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
command mkdir -p "$XDG_DATA_HOME/zinit" && command chmod g-rwX "$XDG_DATA_HOME/zinit"
command git clone https://github.com/zdharma-continuum/zinit "$XDG_DATA_HOME/zinit/zinit.git" && \
print -P "%F{33} %F{34}Installation successful.%f%b" || \
print -P "%F{160} The clone has failed.%f%b"
fi
source "$XDG_DATA_HOME/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit
zinit ice pick"async.zsh" src"pure.zsh"
zinit light sindresorhus/pure
zinit light-mode for \
PZTM::environment \
PZTM::spectrum \
PZTM::editor \
zinit wait lucid blockf light-mode for \
zsh-users/zsh-completions \
zsh-users/zsh-autosuggestions \
zdharma-continuum/fast-syntax-highlighting \
zdharma-continuum/history-search-multi-word \
CyberShadow/per-directory-history \
azu/ni.zsh
### zsh ###
setopt INTERACTIVE_COMMENTS
# history
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_ALLOW_CLOBBER
setopt HIST_IGNORE_SPACE
setopt HIST_NO_FUNCTIONS
setopt HIST_NO_STORE
setopt HIST_REDUCE_BLANKS
setopt HIST_VERIFY
setopt INC_APPEND_HISTORY
setopt SHARE_HISTORY
## per-directory-history
PER_DIRECTORY_HISTORY_TOGGLE='^G'
# directory
setopt AUTO_CD
setopt AUTO_PUSHD
setopt PUSHD_IGNORE_DUPS
setopt PUSHD_SILENT
setopt PUSHD_TO_HOME
setopt CDABLE_VARS
setopt MULTIOS
setopt EXTENDED_GLOB
unsetopt CLOBBER
# correct
setopt CORRECT
alias cd='nocorrect cd'
alias cp='nocorrect cp'
alias grep='nocorrect grep'
alias ln='nocorrect ln'
alias man='nocorrect man'
alias mkdir='nocorrect mkdir -p'
alias mv='nocorrect mv'
alias rm='nocorrect rm'
alias sudo='nocorrect sudo'
# ls
alias ls='ls -G'
alias l='ls -A'
alias ll='ls -lh'
alias la='ll -A'
alias sl='ls'
# network
alias ipen0='ipconfig getifaddr en0'
# homebrew
if [[ $(arch) == "i386" ]]; then
# x86_64
[ -s "/usr/local/bin/brew" ] && eval "$(/usr/local/bin/brew shellenv)"
else
# arm64
[ -s "/opt/homebrew/bin/brew" ] && eval "$(/opt/homebrew/bin/brew shellenv)"
fi
if type brew &>/dev/null; then
if [[ $(arch) == "arm64" ]]; then
# asdf
type asdf &>/dev/null && . $(brew --prefix asdf)/libexec/asdf.sh
# mise
type mise &>/dev/null && eval "$(mise activate zsh)"
# gcloud
if type gloud &>/dev/null; then
source "$(brew --prefix)/share/google-cloud-sdk/path.zsh.inc"
source "$(brew --prefix)/share/google-cloud-sdk/completion.zsh.inc"
fi
# mysql-client
[[ -d "$(brew --prefix)/opt/[email protected]" ]] && export PATH="$(brew --prefix)/opt/[email protected]/bin:$PATH"
fi
FPATH="$(brew --prefix)/share/zsh/site-functions:${FPATH}"
fi
# git
alias gr='cd $(git rev-parse --show-superproject-working-tree --show-toplevel | head -1)'
# gh
if type gh &>/dev/null; then
function gh-pr-worktree() {
git rev-parse 2>/dev/null || {
echo "Not a git repository"
return 1
}
type peco &>/dev/null || {
echo "peco is not installed"
return 1
}
local num branch
IFS=$'\t' read -r num branch <<< "$(gh pr list | peco | cut -f1,3)"
local dir=$(git rev-parse --show-toplevel)
[ ! -z $num ] && git worktree add -B "$branch" "$dir.pr/$num" "origin/$branch"
}
function gh-defaultbranch() {
git rev-parse 2>/dev/null || {
echo "Not a git repository"
return 1
}
defaultbranch=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
[ -z $defaultbranch ] && return 0
git config --local init.defaultBranch $defaultbranch
echo $defaultbranch
}
fi
# ghq
if type ghq &>/dev/null && type peco &>/dev/null; then
function g() {
local dir="$(ghq list | peco)"
[ ! -z $dir ] && cd "$(ghq root)/$dir"
}
fi
# code
if type code &>/dev/null; then
function c() {
local localwsfile="local.code-workspace"
if [ -f "$localwsfile" ]; then
code -n "$localwsfile"
return 0
fi
local wsfile=$(find . -maxdepth 1 -type f -name "*.code-workspace" | head -n 1)
if [ ! -z "$wsfile" ]; then
code -n "$wsfile"
else
code -n .
fi
}
fi
# direnv
type direnv &>/dev/null && eval "$(direnv hook zsh)"
# tre
alias tree='tre'
{{ if eq .chezmoi.os "darwin" -}}
# pbcopy
alias clip='pbcopy'
# tailscale
alias tailscale='/Applications/Tailscale.app/Contents/MacOS/Tailscale'
[[ -f "${fpath[1]}/_tailscale" ]] || tailscale completion zsh > "${fpath[1]}/_tailscale"
# xcode
alias xcode='xed'
alias xcodeclean='rm -rf ~/Library/Developer/Xcode/DerivedData'
{{- end }}
# fvm
[[ -f "$XDG_CONFIG_HOME/.dart-cli-completion/zsh-config.zsh" ]] && . "$XDG_CONFIG_HOME/.dart-cli-completion/zsh-config.zsh" || true
function check-fvm() {
if [[ -d ".fvm" ]]; then
echo "fvm is available"
alias flutter='fvm flutter'
alias dart='fvm dart'
fi
}
check-fvm
# chezmoi
alias cz='chezmoi'
alias czc='code -n $(cz source-path)'
# rust
[[ -d "$HOME/.cargo" ]] && source "$HOME/.cargo/env"
if type rustup &>/dev/null && [[ ! -f $HOME/.zfunc/_rustup ]]; then
command mkdir "$HOME/.zfunc"
rustup completions zsh > "$HOME/.zfunc/_rustup"
rustup completions zsh cargo > "$HOME/.zfunc/_cargo"
fi
# rye
if type rye &>/dev/null && [[ -d "$HOME/.rye" ]]; then
source "$HOME/.rye/shims"
fi
# tabtab source for packages
# uninstall by removing these lines
[[ -f $XDG_CONFIG_HOME/tabtab/zsh/__tabtab.zsh ]] && . $XDG_CONFIG_HOME/tabtab/zsh/__tabtab.zsh || true
# chpwd hook
autoload -Uz add-zsh-hook
add-zsh-hook chpwd check-fvm
# autocompletion
fpath+=$HOME/.zfunc
autoload -Uz compinit && compinit
autoload -U +X bashcompinit && bashcompinit
# ni
compdef _ni ni
# 1password cli
if type op &>/dev/null; then
[[ -f "$XDG_CONFIG_HOME/op/plugins.sh" ]] && source "$XDG_CONFIG_HOME/op/plugins.sh"
eval "$(op completion zsh)"
compdef _op op
fi
# buf
type buf &>/dev/null && eval "$(buf completion zsh)"
# terraform
type terraform &>/dev/null && complete -o nospace -C terraform terraform
# terragrunt
type terragrunt &>/dev/null && complete -o nospace -C terragrunt terragrunt
# jujutsu
type jj &>/dev/null && source <(jj util completion zsh)
# sdkman
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh"