-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_zshrc.tmpl
481 lines (396 loc) · 14.7 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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
# Fig pre block. Keep at the top of this file.
# BEGIN_KITTY_SHELL_INTEGRATION
# END_KITTY_SHELL_INTEGRATION
# Fig post block. Keep at the bottom of this file.
{{- if eq .chezmoi.os "darwin" -}}
[[ -f "$HOME/.fig/shell/bashrc.post.bash" ]] && builtin source "$HOME/.fig/shell/bashrc.post.bash"
{{ end -}}
[[ -f ~/.bash-preexec.sh ]] && source ~/.bash-preexec.sh
export PATH="/usr/local/cuda/bin:$PATH"
export PATH="$HOME/.local/bin:$PATH"
export VCPKG_ROOT="$HOME/codespace/github.com/microsoft/vcpkg/"
export GOPATH=$(go env GOPATH)
export PATH=$PATH:$(go env GOPATH)/bin
# Fig pre block. Keep at the top of this file.
[[ -f "$HOME/.fig/shell/zshrc.pre.zsh" ]] && builtin source "$HOME/.fig/shell/zshrc.pre.zsh"
eval "$(sheldon source)"
### Added by Zinit's installer
# setopt promptsubst
# zinit snippet OMZT::gnzh
# zinit light marlonrichert/zsh-autocomplete
bindkey '\e[A' up-line-or-search
bindkey '\eOA' up-line-or-search
bindkey '^k' up-line-or-search
# up-line-or-search: Open history menu.
# up-line-or-history: Cycle to previous history line.
# Down arrow:
# bindkey '\e[B' down-line-or-select
# bindkey '\eOB' down-line-or-select
# bindkey '^j' down-line-or-select
# down-line-or-select: Open completion menu.
# down-line-or-history: Cycle to next history line.
# zinit load zdharma-continuum/history-search-multi-word
#
# # Two regular plugins loaded without investigating.
# zinit light zsh-users/zsh-autosuggestions
# zinit light zdharma-continuum/fast-syntax-highlighting
#
# zinit ice lucid depth"1" blockf
# # zinit light yuki-ycino/fzf-preview.zsh
#
# zinit snippet OMZP::git
# zinit cdclear -q # <- forget completions provided by Git plugin
export ENCORE_INSTALL="/home/mochi/.encore"
export PATH="$ENCORE_INSTALL/bin:$PATH"
# eval "$(starship init zsh)"
export VOLTA_HOME="$HOME/.volta"
export PATH="/usr/local/bin:$PATH"
export PATH="$VOLTA_HOME/bin:$PATH"
# history
HISTFILE=$HOME/.zsh_history # 履歴を保存するファイル
HISTSIZE=100000 # メモリ上に保存する履歴のサイズ
SAVEHIST=1000000 # 上述のファイルに保存する履歴のサイズ
# share .zshhistory
setopt inc_append_history # 実行時に履歴をファイルにに追加していく
setopt share_history # 履歴を他のシェルとリアルタイム共有する
setopt hist_ignore_all_dups # ヒストリーに重複を表示しない
setopt hist_save_no_dups # 重複するコマンドが保存されるとき、古い方を削除する。
setopt extended_history # コマンドのタイムスタンプをHISTFILEに記録する
setopt hist_expire_dups_first # HISTFILEのサイズがHISTSIZEを超える場合は、最初に重複を削除します
# enable completion
# autoload -Uz compinit; compinit
# autoload -Uz colors colors
# Tabで選択できるように
zstyle ':completion:*:default' menu select=2
#
# コマンドとかでも補完できるようにする
autoload -Uz compinit && compinit
# # 補完で大文字にもマッチ
# zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
#
# # ファイル補完候補に色を付ける
# zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
# ディレクトリ名の補完で末尾の / を自動的に付加し、次の補完に備える
setopt auto_param_slash
# カッコを自動補完
setopt auto_param_keys
# ファイル名の展開でディレクトリにマッチした場合 末尾に / を付加
setopt mark_dirs
# 補完キー連打で順に補完候補を自動で補完
# setopt auto_menu
# スペルミス訂正
setopt correct
# コマンドラインでも # 以降をコメントと見なす
setopt interactive_comments
# コマンドラインの引数で --prefix=/usr などの = 以降でも補完できる
setopt magic_equal_subst
# 語の途中でもカーソル位置で補完
setopt complete_in_word
# 日本語ファイル名を表示可能にする
setopt print_eight_bit
# ディレクトリ名だけでcdする
setopt auto_cd
# ビープ音を消す
setopt no_beep
export EDITOR="nvim"
export VISUAL='nvim'
# fd - cd to selected directory
fcd() {
local dir
dir=$(find ${1:-.} -path '*/\.*' -prune -maxdepth 1 \
-o -type d -print 2> /dev/null | fzf +m) &&
cd "$dir"
}
# fzf --layout=reverse --preview "bat --color=always --style=header,grid --line-range :80 $(ghq root)/{}/(README|readme).*")
fghq(){
local dir
# local ghq_root=$(ghq root)
dir=$(ghq list --full-path | fzf --layout=reverse --preview "bat --color=always --theme Dracula --style=header,grid --line-range :80 $ghq_root/{}/(README|readme|Readme).*")
cd "$dir"
# cd "$dir"
}
updateghq() {
ghq list | ghq get --update --parallel
}
# Another fd - cd into the selected directory
# This one differs from the above, by only showing the sub directories and not
# showing the directories within those.
# fd() {
# DIR=`find * -maxdepth 0 -type d -print 2> /dev/null | fzf-tmux` \
# && cd "$DIR"
# }
# fda - including hidden directories
fda() {
local dir
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir"
}
fshow() {
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
--bind "ctrl-m:execute:
(grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF'
{}
FZF-EOF"
}
# fdr - cd to selected parent directory
fdr() {
local declare dirs=()
get_parent_dirs() {
if [[ -d "${1}" ]]; then dirs+=("$1"); else return; fi
if [[ "${1}" == '/' ]]; then
for _dir in "${dirs[@]}"; do echo $_dir; done
else
get_parent_dirs $(dirname "$1")
fi
}
local DIR=$(get_parent_dirs $(realpath "${1:-$PWD}") | fzf-tmux --tac)
cd "$DIR"
}
# cf - fuzzy cd from anywhere
# ex: cf word1 word2 ... (even part of a file name)
# zsh autoload function
cf() {
local file
file="$(locate -Ai -0 $@ | grep -z -vE '~$' | fzf --read0 -0 -1)"
if [[ -n $file ]]
then
if [[ -d $file ]]
then
cd -- $file
else
cd -- ${file:h}
fi
fi
}
fnvim(){
FILE=`fzf --preview "bat --color=always --style=header,grid --line-range :100 {}"`\
&& nvim "$FILE"
}
function minimal-env-nvim() {
cd "$(mktemp -d)"
export HOME=$PWD
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CACHE_HOME=$HOME/.cache
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
mkdir -p ~/.config/nvim
cat << EOF > ~/.config/nvim/init.vim
syntax enable
filetype plugin indent on
call plug#begin(stdpath('data') . '/plugged')
" Plug ''
call plug#end()
EOF
pwd
ls -la
}
function minimal-env-vim() {
cd "$(mktemp -d)"
export HOME=$PWD
export XDG_CONFIG_HOME=$HOME/.config
export XDG_DATA_HOME=$HOME/.local/share
export XDG_CACHE_HOME=$HOME/.cache
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
mkdir -p ~/.config/nvim
cat << EOF > ~/.vimrc
syntax enable
filetype plugin indent on
call plug#begin(stdpath('data') . '/plugged')
" Plug ''
call plug#end()
EOF
pwd
ls -la
}
function ghq-fzf() {
local src=$(ghq list | fzf --layout=reverse --preview "bat --color=always --style=header,grid --line-range :80 $(ghq root)/{}/(README|readme).*")
if [ -n "$src" ]; then
BUFFER="cd $(ghq root)/$src"
zle accept-line
fi
zle -R -c
}
function geqgets() {
ghq get --shallow
}
zle -N ghq-fzf
bindkey '^]' ghq-fzf
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_COMMAND='rg --files --hidden --glob "!.git"'
export FZF_DEFAULT_OPTS='--height 50% --reverse --border'
function gi() { curl -sLw n https://www.toptal.com/developers/gitignore/api/$@ ;}
# tabtab source for packages
# uninstall by removing these lines
# [[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
# __conda_setup="$('/Users/mochi/opt/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
# if [ $? -eq 0 ]; then
# eval "$__conda_setup"
# else
# if [ -f "/Users/mochi/opt/anaconda3/etc/profile.d/conda.sh" ]; then
# . "/Users/mochi/opt/anaconda3/etc/profile.d/conda.sh"
# else
# export PATH="/Users/mochi/opt/anaconda3/bin:$PATH"
# fi
# fi
# unset __conda_setup
export PATH=/usr/local/Cellar/llvm/11.1.0/bin:$PATH
# export SDKROOT="$(xcrun --sdk macosx --show-sdk-path)"
# export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:~/dotfiles/cpp/include/
# Fig post block. Keep at the bottom of this file.
[[ -f "$HOME/.fig/shell/zshrc.post.zsh" ]] && builtin source "$HOME/.fig/shell/zshrc.post.zsh"
# pnpm
export PNPM_HOME="/Users/mochi/Library/pnpm"
export PATH="$PNPM_HOME:$PATH"
alias bell='afplay /System/Library/Sounds/Funk.aiff'
_notify-done() {
osascript -e 'display notification "Process is done!!!!!!!!!!!!!!!1" with title "Terminal"'
}
alias notify-done=_notify-done
alias "$"=""
# プロセスが終わったら知らせる
alias ds="(notify-done&bell)"
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias .....='cd ../../../..'
# pnpm end
# nof completion --shell=zsh > /usr/local/share/zsh/site-functions/_nof
# eval "$(atuin init zsh)"
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
# #-------------------------------------------------------------------------------
# # Automatic activate/deactivate python virtual environment
# #-------------------------------------------------------------------------------
# function cd() {
# # Call the built-in cd command
# builtin cd "$@" || return
#
# # Deactivate virtual environment
# if [[ -n "$VIRTUAL_ENV" && $PWD != ${VIRTUAL_ENV%/*} && $PWD != ${VIRTUAL_ENV%/*}/* ]]
# then
# deactivate
# fi
#
# # Recursively find virtual env in parent directories
# find_venv_in_parents $PWD
# }
# #-------------------------------------------------------------------------------
# function find_venv_in_parents() {
# local dir=$1
# local venv_path="$dir/.venv"
# local pyvenv_cfg="$venv_path/pyvenv.cfg"
#
# # Check for pyvenv.cfg in the .venv directory
# if [[ -f $pyvenv_cfg ]]; then
# source "$venv_path/bin/activate"
#
# elif [[ -d $venv_path ]]; then
# # Enumerate directories, including dotfiles
# setopt LOCAL_OPTIONS NULL_GLOB
# local dirs=($(ls -d "$venv_path/"*))
# local num_dirs=${#dirs[@]}
#
# # If there's no directory, ignore it and recursively check the parent
# if (( num_dirs == 0 )); then
# if [[ $dir != '/' ]]; then
# find_venv_in_parents "$(dirname "$dir")"
# fi
#
# # If there's only one directory, activate it
# elif (( num_dirs == 1 )); then
# source "${dirs[1]}/bin/activate"
#
# # If there are multiple directories, use peco to select one and activate it
# elif (( num_dirs > 1 )); then
# local selected_dir=$(printf '%s\n' "${dirs[@]}" | peco)
# if [[ $selected_dir == $venv_path/* ]]; then
# source "$selected_dir/bin/activate"
# fi
# fi
# else
# # If we are not in the root directory, recursively check the parent
# if [[ $dir != '/' ]]; then
# find_venv_in_parents "$(dirname "$dir")"
# fi
# fi
# }
#-------------------------------------------------------------------------------
# export PYENV_ROOT="$HOME/.pyenv"
# command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
# eval "$(pyenv init -)"
#
# # Restart your shell for the changes to take effect.
#
# # Load pyenv-virtualenv automatically by adding
# # the following to ~/.bashrc:
#
# eval "$(pyenv virtualenv-init -)"
# export PATH="$PYENV_ROOT/versions/anaconda3-2023.03/bin/:$PATH
# export PATH="$HOME/.rbenv/bin:$PATH"
# export PATH="$(rbenv root)/shims:$PATH"
# eval "$(rbenv init - zsh)"
# rust
. "$HOME/.cargo/env" # For sh/bash/zsh/ash/dash/pdksh
# bun completions
[ -s "/home/mochi/.bun/_bun" ] && source "/home/mochi/.bun/_bun"
# bun
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
# export NVM_DIR="$HOME/.nvm"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
# Wasmer
export WASMER_DIR="/home/mochi/.wasmer"
[ -s "$WASMER_DIR/wasmer.sh" ] && source "$WASMER_DIR/wasmer.sh"
# asdf
. /opt/asdf-vm/asdf.sh
export GEM_HOME=$(ruby -e 'print Gem.user_dir')
export PATH=$GEM_HOME/bin:$PATH
{{ if eq .chezmoi.os "linux" }}
{{ if (.chezmoi.kernel.osrelease | lower | contains "microsoft") }}
# this is a wsl codes
export DISPLAY=$(ip route | awk '/^default/{print $3; exit}'):0
# WSL?
function open() {
if [ $# != 1 ]; then
explorer.exe .
else
if [ -e $1 ]; then
cmd.exe /c start $(wslpath -w $1) 2> /dev/null
else
echo "open: $1 : No such file or directory"
fi
fi
}
#C:\Program Files\PowerShell\7\pwsh.exe
export BROWSER="pwsh.exe /c start $(wslpath -w $(realpath $1))"
export LD_LIBRARY_PATH="/usr/lib/wsl/lib:/usr/local/cuda/lib64:/usr/lib/wsl/lib:"
export BROWSER="'/mnt/c/Program Files/PowerShell/7/pwsh.exe' /c start"
alias open="'/mnt/c/Program Files/PowerShell/7/pwsh.exe' /c start"
export PATH="$PATH:/mnt/c/Users/mochi/AppData/Local/Microsoft/WindowsApps"
export PATH="$PATH:/mnt/c/Users/mochi/AppData/Local/Programs/Microsoft VS Code/bin"
export PATH="$PATH:/mnt/c/Program Files/Docker/Docker/resources/bin"
export PATH="$PATH:/mnt/c/ProgramData/DockerDesktop/version-bin"
export PATH="$PATH:/mnt/c/WINDOWS"
export PATH="$PATH:/mnt/c/WINDOWS/system32"
export PATH="$PATH:/mnt/c/Users/mochi/scoop/shim"
export PATH="$PATH:/mnt/c/Windows/System32/WindowsPowerShell/v1.0"
{{ end }}
{{ end }}