-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdot_zshrc.lazy.tmpl
1127 lines (1012 loc) · 35.1 KB
/
dot_zshrc.lazy.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
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# cSpell:disable
#--------------------------------------------------------------
# path , alias
#--------------------------------------------------------------
alias gb='git branch'
alias gf='git fetch -p'
alias ll='ls -l'
alias la='ls -la'
alias mh='make help'
alias nr='npm run'
alias vim='nvim'
#--------------------------------------------------------------
# plugin
#--------------------------------------------------------------
# https://github.com/zdharma-continuum/zinit?tab=readme-ov-file#ice-modifiers
# wait = 遅延読み込み wait"0"と同義
# lucid = プラグイン読込時の表示をOFF
# blockf = プラグインによる$pathの変更を禁止する
# light-mode = for構文におけるzinit light(light-modeがない場合はzinit snippet相当)
# as"program" = zshプラグインでないものを読込(ソースを$pathに追加)
# as"completion" = 補完プラグインとして追加
# from = clone先を指定 [from"github"(デフォルト)/from"gh-r"(Github Release)]
# bpick= gh-rするファイル名を指定 [例.bpick"nnn-v*"]
# mv = ファイルをmv
# cp = ファイルをcp
# atclone= clone後に実行する関数を指定
# atpull= pull後(upgrade)に実行する関数を指定 [atpull"%atclone" = atcloneの内容を実行]
# configure=./configureを実行、make前に実行の場合はconfigure'!'
# make= make install、インストール先を指定するにはmake PREFIX=$ZPFX
# rustup = rust installer
# cargo = rust builder and package manager
# (plugin script loading)
# src = 読込完了時に指定ファイル読込
# atload = 読込完了時に実行する関数を指定
# pick = 引数に与えられたものを$pathに追加
# sbin = 引数に与えられたものを$pathに追加
# 実行順:atinit -> atpull! -> make'!!' -> mv -> cp -> make! -> atclone/atpull -> make -> (plugin script loading) -> src -> multisrc -> atload.
# https://github.com/zdharma-continuum/zinit?tab=readme-ov-file#order-of-execution
### command ###
# asdf #
# __asdf_atclone() {
# asdf plugin add act
# asdf plugin add chezmoi
# asdf plugin add golang
# asdf plugin add nodejs
# asdf plugin add python
# asdf plugin add ruby
# asdf plugin add tmux
# asdf plugin add vim
# }
# __asdf_atload() {
# export ASDF_GOLANG_MOD_VERSION_ENABLED=true
# export ASDF_DATA_SHIMS="$HOME/.asdf/shims"
# export ASDF_DATA_INSTALLS="$HOME/.asdf/installs"
# export ASDF_CONFIG_FILE="$HOME/.config/asdf/.asdfrc"
# export PATH="$ASDF_DATA_SHIMS:$ASDF_DATA_INSTALLS:$PATH"
# }
# zinit wait lucid light-mode blockf for \
# src"asdf.sh" \
# atclone"__asdf_atclone" \
# atload"__asdf_atload" \
# @'asdf-vm/asdf'
# atuin #
__atuin_atload() {
eval "$(atuin init zsh --disable-up-arrow --disable-ctrl-r)"
export ATUIN_CONFIG_DIR="$HOME/.config/atuin"
}
{{ if eq .chezmoi.os "darwin" -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v18.0.1" \
sbin"atuin*/atuin" \
atclone"atuin gen-completions --shell zsh > _atuin" atpull"%atclone" \
atload"__atuin_atload" \
@'atuinsh/atuin'
{{ else }}
zinit wait lucid light-mode blockf for \
from"gh-r" bpick"*x86_64-unknown-linux-musl*" \
ver"v18.0.1" \
sbin"atuin*/atuin" \
atclone"atuin gen-completions --shell zsh > _atuin" atpull"%atclone" \
atload"__atuin_atload" \
@'atuinsh/atuin'
{{- end }}
# bat #
__bat_atload() {
export BAT_THEME="Monokai Extended"
}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.23.0" \
sbin"bat*/bat" \
cp"bat*/autocomplete/bat.zsh -> _bat" \
atload"__bat_atload" \
@'sharkdp/bat'
# Clipboard #
# __clipboard_atload() {
# export CLIPBOARD_SILENT=1
# }
# zinit wait lucid light-mode blockf for \
# from"gh-r" \
# sbin"bin/cb" \
# atload"__clipboard_atload" \
# @'Slackadays/Clipboard'
zinit wait lucid light-mode blockf for \
atclone"go build cmd/gocopy/gocopy.go && go build cmd/gopaste/gopaste.go" atpull"%atclone" \
sbin"gocopy -> gocopy" \
sbin"gopaste -> gopaste" \
@'atotto/clipboard'
# delta #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"0.16.5" \
sbin"delta*/delta" \
atload"compdef _gnu_generic delta" \
@'dandavison/delta'
# diffnav #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.2.8" \
sbin"diffnav" \
@'dlvhdr/diffnav'
# difftastic #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"0.54.0" \
sbin"difft" \
@'Wilfred/difftastic'
# dura #
zinit wait lucid light-mode blockf for \
cargo"dura" \
sbin"bin/dura" \
@'tkellogg/dura'
# fzf #
__fzf_atload() {
export FZF_DEFAULT_COMMAND='find $PWD -type d -path "$PWD/.*" -prune -o -not -name ".*" -type f -name "*" -print'
{{ if eq .chezmoi.os "darwin" -}}
export FZF_DEFAULT_OPTS='-m --height 40% --layout=reverse --border --bind ctrl-k:kill-line,alt-right:forward-word,alt-left:backward-word'
{{ else -}}
export FZF_DEFAULT_OPTS='-m --height 40% --layout=reverse --border'
bindkey "^[R" fzf-history-widget # alt + shift + r
bindkey -r "^R"
{{- end }}
}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.55.0" \
sbin"fzf" \
atload"__fzf_atload" \
@'junegunn/fzf'
zinit wait lucid blockf for \
"https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh" \
"https://github.com/junegunn/fzf/blob/master/shell/completion.zsh"
# fx #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"30.1.0" \
sbin"fx* -> fx" \
@'antonmedv/fx'
# ghq #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v1.4.2" \
sbin"*/ghq" \
@'x-motemen/ghq'
# gitui #
zinit wait lucid light-mode blockf for \
from"gh-r" cargo"gitui" \
ver"v0.22.1" \
sbin"gitui" \
@'extrawurst/gitui'
# github-cli #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v2.55.0" \
sbin"gh*/bin/gh" \
atclone"./gh*/bin/gh completion -s zsh >_gh" atpull"%atclone" \
@'cli/cli'
# gh-extension(gh-poi) #
{{ if eq .chezmoi.os "darwin" -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.10.1" \
sbin"darwin* -> gh-poi" \
@'seachicken/gh-poi'
{{ else -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.10.1" \
sbin"linux* -> gh-poi" \
@'seachicken/gh-poi'
{{- end }}
# glow #
__glow_atclone() {
{{ if eq .chezmoi.os "darwin" -}}
[ -e "$HOME/.config/glow/glow.yml" ] && ln -f "$HOME/.config/glow/glow.yml" "$HOME/Library/Preferences/glow/glow.yml"
{{- end }}
}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v1.5.1" \
sbin"glow" \
atclone"__glow_atclone" \
@'charmbracelet/glow'
# ijq #
zinit wait lucid light-mode blockf for \
make \
sbin"ijq -> ijq" \
@'gpanders/ijq'
# jq #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"jq-1.6" \
sbin"jq* -> jq" \
@'jqlang/jq'
# koji #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v3.0.0" \
sbin"koji* -> koji" \
@'cococonscious/koji'
# lazydocker #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.23.1" \
sbin"lazydocker* -> lazydocker" \
@'jesseduffield/lazydocker'
# mise #
__mise_atload() {
# czg
[ -e "$HOME/.config/commitizen/.czrc" ] && [ -z "$HOME/.czrc" ] && ln -f "$HOME/.config/commitizen/.czrc" "$HOME/.czrc"
[ -e "$HOME/.config/commitizen/.commitlintrc.js" ] && [ -z "$HOME/.commitlintrc.js" ] && ln -f "$HOME/.config/commitizen/.commitlintrc.js" "$HOME/.commitlintrc.js"
# mise
eval "$(mise activate zsh)"
}
{{ if eq .chezmoi.os "darwin" -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v2024.12.24" \
bpick"mise*-x64" \
bpick"mise*-arm64" \
sbin"mise*-arm64 -> mise" \
sbin"mise*macos-x64 -> mise-x64" \
atload"__mise_atload" \
@'jdx/mise'
{{ else -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v2024.12.24" \
sbin"mise* -> mise" \
atload"__mise_atload" \
@'jdx/mise'
{{- end }}
# navi #
# atload"eval $(navi widget zsh)" \
__navi_atclone() {
[ -e "$HOME/.config/navi/config.yaml" ] && \
[ -e "$(navi info config-path)" ] && \
[ "$HOME/.config/navi/config.yaml" = "$(navi info config-path)" ] && \
ln -s "$HOME/.config/navi/config.yaml" "$(navi info config-path)"
}
zinit wait lucid light-mode blockf for \
from"gh-r" cargo"navi" \
ver"v2.22.1" \
sbin"navi" \
atclone"__navi_atclone" \
@'denisidoro/navi'
# tig #
{{ if eq .chezmoi.os "darwin" -}}
zinit wait lucid light-mode blockf for \
atclone"make configure && make prefix=$ZPFX install-release-doc" \
atpull"%atclone" \
ver"tig-2.5.10" \
configure"!" \
make"install PREFIX=$ZPFX" \
@'jonas/tig'
{{- end }}
# tgpt #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v2.7.1" \
sbin"tgpt* -> tgpt" \
@'aandrew-me/tgpt'
# spacer #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.3.0" \
sbin"spacer* -> spacer" \
@'samwho/spacer'
# ugrep #
{{ if eq .chezmoi.os "darwin" -}}
zinit wait lucid light-mode blockf for \
configure"!" \
make"all install PREFIX=$ZPFX" \
pick"bin/ug bin/ugrep" \
sbin"bin/ug -> ug" \
sbin"bin/ugrep -> ugrep" \
@'Genivia/ugrep'
{{ else -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v4.4.1" \
sbin"ug* -> ug" \
sbin"ugrep* -> ugrep" \
@'Genivia/ugrep'
{{- end }}
# up #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.4" \
sbin"up* -> up" \
@'akavel/up'
# yazi #
{{ if eq .chezmoi.os "darwin" -}}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.2.5" \
sbin"yazi*/yazi -> yazi" \
@'sxyazi/yazi'
{{ else -}}
# NOTE:version `GLIBC_2.33' not foundのエラー回避のため暫定的にversion固定
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.1.4" \
sbin"yazi* -> yazi" \
@'sxyazi/yazi'
{{- end }}
# z #
#__z_atload() {
# export _Z_DATA="$HOME/.local/state/z/.z"
#}
#zinit wait lucid light-mode blockf for \
# as"program" pick"z" \
# src"z.sh" cp"z.sh -> z" \
# atload"__z_atload" \
# rupa/z
# zabrze #
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.3.0" \
as"program" \
atload'eval "$(zabrze init --bind-keys)"' \
@'Ryooooooga/zabrze'
# zoxide #
__zoxide_atload() {
mkdir -p "$HOME/.local/state/zoxide" 2>/dev/null
export _ZO_DATA_DIR="$HOME/.local/state/zoxide"
eval "$(zoxide init zsh --cmd j)"
}
zinit wait lucid light-mode blockf for \
from"gh-r" \
ver"v0.9.2" \
sbin"zoxide" \
atload"__zoxide_atload" \
@'ajeetdsouza/zoxide'
{{ if eq .chezmoi.os "darwin" -}}
# blueutil #
zinit wait lucid light-mode blockf for \
make \
sbin"blueutil" \
@'toy/blueutil'
{{- end }}
## programs ##
# git-jump #
zinit wait lucid light-mode blockf for \
as"program" pick"git-jump" \
"https://github.com/git/git/blob/master/contrib/git-jump/git-jump"
zinit wait lucid light-mode blockf for \
as"program" pick"fzf-tmux" \
"https://github.com/junegunn/fzf/blob/master/bin/fzf-tmux"
### node ###
# __node_atclone() {
# [ -e "$HOME/.config/commitizen/.czrc" ] && ln -f "$HOME/.config/commitizen/.czrc" "$HOME/.czrc"
# [ -e "$HOME/.config/commitizen/.commitlintrc.js" ] && ln -f "$HOME/.config/commitizen/.commitlintrc.js" "$HOME/.commitlintrc.js"
# }
# zinit wait lucid light-mode blockf for \
# node"!cspell -> cspell" \
# atclone"__node_atclone" \
# @'ryo246912/null3'
#
# zinit wait lucid light-mode blockf for \
# node"!czg -> czg" \
# @'ryo246912/null'
#
# zinit wait lucid light-mode blockf for \
# node"!open-cli -> open-cli" \
# @'ryo246912/null1'
### python ###
# zinit wait lucid light-mode blockf for \
# pip"!gita -> gita" \
# @'ryo246912/null2'
#
# zinit wait lucid light-mode blockf for \
# pip"deepl <- !deepl-cli -> deepl" \
# @'ryo246912/null4'
### plugin ###
__zsh-autosuggestions_atload() {
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=100"
_zsh_autosuggest_start
}
zinit wait lucid light-mode blockf for \
atload"__zsh-autosuggestions_atload" \
@'zsh-users/zsh-autosuggestions'
zinit wait lucid light-mode blockf for \
atload"source autopair.zsh && autopair-init" \
@'hlissner/zsh-autopair'
{{ if eq .chezmoi.os "darwin" -}}
__zsh-auto-notify_atload() {
export AUTO_NOTIFY_THRESHOLD=20
AUTO_NOTIFY_IGNORE+=("czg" "chezmoi apply" "gitui")
}
zinit wait lucid light-mode blockf for \
atload"__zsh-auto-notify_atload" \
@'MichaelAquilina/zsh-auto-notify'
{{- end}}
zinit wait lucid light-mode blockf for \
@'zdharma/fast-syntax-highlighting'
# zinit wait lucid light-mode blockf for \
# @'olets/zsh-abbr'
### completion ###
zinit wait lucid light-mode blockf for \
as"completion" \
atload"zicompinit; zicdreplay" cp"git-completion.zsh -> _git" \
"https://github.com/git/git/blob/master/contrib/completion/git-completion.zsh"
zinit wait lucid light-mode blockf for \
silent \
atclone"zstyle ':completion:*:*:git:*' script git-completion.bash" atpull"%atclone" \
"https://github.com/git/git/blob/master/contrib/completion/git-completion.bash"
zinit wait lucid light-mode blockf for \
as"completion" "https://github.com/docker/cli/blob/master/contrib/completion/zsh/_docker"
zinit wait lucid light-mode blockf for \
as"completion" "https://raw.githubusercontent.com/docker/compose/1.29.2/contrib/completion/zsh/_docker-compose"
zinit wait lucid light-mode blockf for \
as"completion" "https://github.com/Homebrew/brew/blob/master/completions/zsh/_brew"
zinit wait lucid light-mode blockf for \
as"completion" "https://github.com/jarun/nnn/blob/master/misc/auto-completion/zsh/_nnn"
zinit wait lucid light-mode blockf for \
src"tmux" \
as"completion" "https://github.com/imomaliev/tmux-bash-completion/blob/master/completions/tmux"
zinit wait lucid light-mode blockf for \
atload"source zsh-better-npm-completion.plugin.zsh" \
as"completion" "https://github.com/lukechilds/zsh-better-npm-completion/blob/master/zsh-better-npm-completion.plugin.zsh"
# zinit wait lucid light-mode blockf for \
# as"completion" "https://github.com/nosarthur/gita/blob/master/auto-completion/zsh/_gita" \
# as"completion" "https://github.com/nosarthur/gita/blob/master/auto-completion/zsh/.gita-completion.zsh"
zinit wait lucid light-mode blockf for \
as"completion" "https://github.com/jdx/mise/blob/main/completions/_mise"
zinit wait lucid light-mode blockf for \
mv"chezmoi.zsh -> _chezmoi" \
as"completion" "https://github.com/twpayne/chezmoi/blob/master/completions/chezmoi.zsh"
#--------------------------------------------------------------
# fzf-function
#--------------------------------------------------------------
{{ if eq .chezmoi.os "darwin" -}}
# fcb - fuzzy chrome bookmark
fcb() {
bookmarks_path="$HOME/Library/Application Support/Google/Chrome/Profile 1/Bookmarks"
jq_script='
def ancestors: while(. | length >= 2; del(.[-1,-2]));
. as $in | paths(.url?) as $key | $in | getpath($key) | {name,url, path: [$key[0:-2] | ancestors as $a | $in | getpath($a) | .name?] | reverse | join("/") } | .path + "/" + .name + "\t" + .url'
jq -r "$jq_script" < "$bookmarks_path" \
| sed -E $'s/(.*)\t(.*)/\\1\t\x1b[36m\\2\x1b[m/g' \
| fzf --ansi \
| cut -d$'\t' -f2 \
| xargs open
}
# fch - fuzzy chrome history
fch() {
local cols sep google_history open
cols=$(( COLUMNS / 3 ))
sep='{::}'
if [ "$(uname)" = "Darwin" ]; then
google_history="$HOME/Library/Application Support/Google/Chrome/Profile 1/History"
open=open
else
google_history="$HOME/.config/google-chrome/Profile 1/History"
open=xdg-open
fi
cp -f "$google_history" /tmp/h
sqlite3 -separator $sep /tmp/h \
"select substr(title, 1, $cols), url
from urls order by last_visit_time desc" |
awk -F $sep '{printf "%-'$cols's \x1b[36m%s\x1b[m\n", $1, $2}' |
fzf --ansi --multi | sed 's#.*\(https*://\)#\1#' | xargs $open > /dev/null 2> /dev/null
}
{{- end }}
# ff - fuzzy find
ff() {
find ${1:-.} | fzf | tr -d '\n' | cb
}
# fgb - fuzzy git branch
fgb() {
git for-each-ref --format='%(refname:short) %09 %(committername) %09 %(committerdate:format:%Y/%m/%d %H:%M) %09 %(objectname:short)' | column -ts $'\t' | fzf | awk '{ print $1 }' | tr -d '\n' | cb
}
# fgc - fuzzy git checkout branch
fgc() {
git branch --format='%(refname:short) %09 %(committername) %09 %(committerdate:format:%Y/%m/%d %H:%M) %09 %(objectname:short)' | column -ts $'\t' | fzf | awk '{ print $1 }' | xargs -I % git checkout %
}
# fgh - fuzzy git hash copy
fgh() {
local commits commit
commits=$(git log --oneline) &&
commit=$(echo "$commits" | fzf --preview "git show {1} | delta --no-gitconfig") &&
$(echo "$commit" | awk '{print $1}' | tr -d '\n' | cb)
}
# fghd - fuzzy git hash diff copy
fghd() {
local commits commit1 commit2
commits=$(git log --oneline) &&
commit1=$(echo "$commits" | fzf | awk '{print $1}') &&
commit2=$(echo "$commits" | fzf --preview "git diff "$commit1...{1}" | delta --no-gitconfig" | awk '{print $1}') &&
git diff "$commit1...$commit2" | delta &&
$(echo "$commit1...$commit2" | tr -d '\n' | cb)
}
# fnr - fuzzy npm run
fnr() {
local script
script=$(cat package.json | jq -r '.scripts | to_entries[] | [.key,.value] | @csv' | column -t -s, | fzf | awk '{print $1}' | tr -d '"') &&
if [ -n "$script" ]; then
npm run $script
fi
}
# fz - fuzzy z command
#fz() {
# local res=$(z | sort -rn | cut -c 12- | fzf)
# if [ -n "$res" ]; then
# cd $res
# else
# return 1
# fi
#}
#--------------------------------------------------------------
# zsh widget
#--------------------------------------------------------------
# ctrl + d(alt + shift + d)でgitui起動
_gitui() {
if [ -n "$TMUX" ]; then
tmux popup -xC -yC -w95% -h95% -E -d "#{pane_current_path}" gitui
else
BUFFER='gitui'
zle accept-line
fi
}
zle -N _gitui
{{ if eq .chezmoi.os "darwin" -}}
bindkey "^D" _gitui
{{ else }}
bindkey "^[D" _gitui
{{- end }}
# ctrl + n(alt + shift + n)でnnn起動
_nnn() {
BUFFER='nnn -dHUx'
zle accept-line
}
zle -N _nnn
{{ if eq .chezmoi.os "darwin" -}}
bindkey "^N" _nnn
{{ else }}
bindkey "^[N" _nnn
{{- end }}
# ctrl + y(alt + shift + y)でyazi起動
_yazi() {
if [ -n "$TMUX" ]; then
tmux popup -xC -yC -w95% -h95% -E -d "#{pane_current_path}" yazi
else
BUFFER='yazi'
zle accept-line
fi
}
zle -N _yazi
{{ if eq .chezmoi.os "darwin" -}}
bindkey "^Y" _yazi
{{ else }}
bindkey "^[Y" _yazi
{{- end }}
# ctrl + g(alt + shift + g)でnavi widgetを呼び出し
_custom_navi_widget() {
# [-b:buffer name][-d:delete buffer][-r:LFを自動で置換しない][-p:paste時にコマンドを自動で実行しない][-t:target pane]
#後方の空白文字を削除 ${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
#前方の空白文字を削除 ${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
#複数の連続した空白を1つにする sed -e "s/ */ /g"
if [ -n "$TMUX" ]; then
{{ if eq .chezmoi.os "darwin" -}}
tmux popup -xC -y "#{popup_pane_bottom}" -d "#{pane_current_path}" -w95% -h40% -E '\
window=$(tmux display -p -F "#S:#I.#P") && \
export FZF_DEFAULT_OPTS="-m --layout=reverse --border" && \
TMP_BUFFER=$(navi --print) && \
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"} && \
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"} && \
TMP_BUFFER=$((tr "\n" " " | sed -e "s/ */ /g") <<< "$TMP_BUFFER") && \
tmux set-buffer -b tmp "$TMP_BUFFER" && \
tmux paste-buffer -drp -t $window -b tmp \
'
{{ else }}
tmux popup -xC -y "#{popup_pane_bottom}" -d "#{pane_current_path}" -w95% -h40% -E '\
window=$(tmux display -p -F "#S:#I.#P") && \
export FZF_DEFAULT_OPTS="-m --layout=reverse --border" && \
TMP_BUFFER=$(navi --print) && \
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"} && \
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"} && \
tmux set-buffer -b tmp "$TMP_BUFFER" && \
tmux paste-buffer -drp -t $window -b tmp \
'
{{- end }}
else
local TMP_BUFFER
#後方の空白文字を削除 ${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
#前方の空白文字を削除 ${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
#複数の連続した空白を1つにする sed -e "s/ */ /g"
TMP_BUFFER=$(navi --print) && \
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"} && \
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"} && \
TMP_BUFFER=$((tr "\n" " " | sed -e "s/ */ /g") <<< "$TMP_BUFFER")
BUFFER="$TMP_BUFFER"
CURSOR=$#BUFFER #カーソルを末尾に移動
zle redisplay
fi
}
zle -N _custom_navi_widget
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^G' _custom_navi_widget
{{ else }}
bindkey '^[G' _custom_navi_widget
{{- end }}
# ctrl + q → ctrl + q(alt + shift + q → alt + shift + q)でnaviに登録されたpipe commandのsnippet呼び出し
_navi_insert_pipe_snippet() {
#後方の空白文字を削除 ${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
#前方の空白文字を削除 ${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
#複数の連続した空白を1つにする sed -e "s/ */ /g"
local word
if [ -n "$TMUX" ]; then
tmux popup -xC -y "#{popup_pane_bottom}" -d "#{pane_current_path}" -w95% -h40% -E '\
export FZF_DEFAULT_OPTS="-m --layout=reverse --border" && \
TMP_BUFFER=$(navi --print --query "shell:pipe-command ") && \
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"} && \
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"} && \
TMP_BUFFER=$((tr "\n" " " | sed -e "s/ */ /g") <<< "$TMP_BUFFER") && \
tmux set-buffer -b tmp "$TMP_BUFFER" \
'
if tmux show-buffer -b tmp > /dev/null 2>&1 ; then
word=$(tmux show-buffer -b tmp)
fi
tmux delete-buffer -b tmp
else
#後方の空白文字を削除 ${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
#前方の空白文字を削除 ${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
word=$(navi --print --query "shell:pipe-command ") && \
word=${word%"${word##*[![:space:]]}"} && \
word=${word#"${word%%[![:space:]]*}"} && \
word=$((tr "\n" " " | sed -e "s/ */ /g") <<< "$word")
fi && \
if [ -n "$word" ] && [[ $word =~ ">" ]] ; then
BUFFER="$BUFFER $word"
CURSOR=$#BUFFER #カーソルを末尾に移動
elif [ -n "$word" ] ; then
BUFFER="$BUFFER | $word"
CURSOR=$#BUFFER #カーソルを末尾に移動
fi
zle redisplay
}
zle -N _navi_insert_pipe_snippet
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^Q^Q' _navi_insert_pipe_snippet
{{ else }}
bindkey '^[Q^[Q' _navi_insert_pipe_snippet
{{- end }}
# ctrl + q → ctrl + a(alt + shift + q → alt + shift + a)で余分な空白を削除
_delete_space() {
local TMP_BUFFER
TMP_BUFFER=$BUFFER
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"} #後方の空白文字を削除
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"} #前方の空白文字を削除
TMP_BUFFER=$((tr "\n\t" " " | sed -e 's/ */ /g') <<< "$TMP_BUFFER") #複数の連続した空白を1つにする
BUFFER=$TMP_BUFFER
zle redisplay
}
zle -N _delete_space
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^Q^A' _delete_space
{{ else }}
bindkey '^[Q^[A' _delete_space
{{- end }}
# ctrl + q → ctrl + z(alt + shift + q → alt + shift + z)でコマンド履歴を選択して出力
_fzf_insert_command() {
local num command line array1 array2 word
command=$(cat <(echo "$BUFFER") <(history -100000 | cut -f 4- -d " " | tac) | fzf)
if [ -n "$command" ] ; then
BUFFER="$BUFFER $command"
CURSOR=$#BUFFER #カーソルを末尾に移動
fi
zle redisplay
}
zle -N _fzf_insert_command
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^Q^Z' _fzf_insert_command
{{ else }}
bindkey '^[Q^[Z' _fzf_insert_command
{{- end }}
# ctrl + q → ctrl + x(alt + shift + q → alt + shift + x)でコマンド履歴からwordを選択して出力
_fzf_insert_command_word() {
local num command line array1 array2 word
command=$(cat <(echo "$BUFFER") <(history -100000 | cut -f 4- -d " " | tac) | fzf)
if [ -n "$command" ] ; then
for i in $(seq $(echo "$command" | wc -m)) ; do
array1+=( "$(cut -c $i- <(echo $command))\n" )
done
fi
if [ -n "${array1[*]}" ] ; then
line=$(echo -e "${array1[@]}" | fzf)
num=$(echo "$line" | wc -m)
for j in $(seq $num) ; do
array2+=( "$(cut -c -$((num-j+1)) <(echo $line))\n" )
done
fi
if [ -n "${array2[*]}" ] ; then
word=$(echo -e "${array2[@]}" | fzf)
word=${word#"${word%%[![:space:]]*}"} #前方の空白文字を削除
word=${word%"${word##*[![:space:]]}"} #後方の空白文字を削除
word=$(echo "$word" | tr -d '\n')
fi
if [ -n "$word" ] ; then
BUFFER="$BUFFER $word"
CURSOR=$#BUFFER #カーソルを末尾に移動
fi
zle redisplay
}
zle -N _fzf_insert_command_word
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^Q^X' _fzf_insert_command_word
{{ else }}
bindkey '^[Q^[X' _fzf_insert_command_word
{{- end }}
# ctrl + q → ctrl + w(alt + shift + q → alt + shift + w)で画面キャプチャしてwordを選択してコピー
_copy_word() {
local num line1 line2 array1 array2 word
line1=$(tmux capture-pane -p | fzf)
if [ -n "$line1" ] ; then
for i in $(seq $(echo "$line1" | wc -m)) ; do
array1+=( "$(cut -c $i- <(echo $line1))\n" )
done
fi
if [ -n "${array1[*]}" ] ; then
line2=$(echo -e "${array1[@]}" | fzf)
num=$(echo "$line2" | wc -m)
for j in $(seq $num) ; do
array2+=( "$(cut -c -$((num-j+1)) <(echo $line2))\n" )
done
fi
if [ -n "${array2[*]}" ] ; then
word=$(echo -e "${array2[@]}" | fzf)
word=${word%"${word##*[![:space:]]}"} #後方の空白文字を削除
word=${word#"${word%%[![:space:]]*}"} #前方の空白文字を削除
fi
if [ -n "$word" ] ; then
echo "$word" | tr -d '\n' | cb
fi
zle redisplay
}
zle -N _copy_word
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^Q^W' _copy_word
{{ else }}
bindkey '^[Q^[W' _copy_word
{{- end }}
# ctrl + q → ctrl + s(alt + shift + q → alt + shift + s)でshortcut表示
_shortcut() {
if [ -n "$TMUX" ]; then
tmux popup -xC -y "#{popup_pane_bottom}" -d "#{pane_current_path}" -w95% -h40% -E '\
export FZF_DEFAULT_OPTS="-m --layout=reverse --border" && \
cat ~/.config/shortcut/my_shortcut.csv | column -t -s, | fzf --no-sort --layout=reverse --border
'
else
cat ~/.config/shortcut/my_shortcut.csv | column -t -s, | fzf --no-sort --layout=reverse --border
fi
}
zle -N _shortcut
bindkey '^Q^S' _shortcut
# ctrl + q → ctrl + g(alt + shift + q → alt + shift + g)でnaviのコマンドをクリップボードにコピー
_navi_copy_snippet() {
# [-b:buffer name][-d:delete buffer][-r:LFを自動で置換しない][-p:paste時にコマンドを自動で実行しない][-t:target pane]
#後方の空白文字を削除 ${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
#前方の空白文字を削除 ${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
#複数の連続した空白を1つにする sed -e "s/ */ /g"
if [ -n "$TMUX" ]; then
tmux popup -xC -y "#{popup_pane_bottom}" -d "#{pane_current_path}" -w95% -h40% -E '\
export FZF_DEFAULT_OPTS="-m --layout=reverse --border" && \
TMP_BUFFER=$(navi --print) && \
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"} && \
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"} && \
TMP_BUFFER=$((tr "\n" " " | sed -e "s/ */ /g") <<< "$TMP_BUFFER") && \
tmux set-buffer -b tmp "$TMP_BUFFER" \
'
if tmux show-buffer -b tmp > /dev/null 2>&1 ; then
tmux show-buffer -b tmp | cb
fi && \
tmux delete-buffer -b tmp
else
#後方の空白文字を削除 ${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
#前方の空白文字を削除 ${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
TMP_BUFFER=$(navi --print)
TMP_BUFFER=${TMP_BUFFER%"${TMP_BUFFER##*[![:space:]]}"}
TMP_BUFFER=${TMP_BUFFER#"${TMP_BUFFER%%[![:space:]]*}"}
TMP_BUFFER=$((tr "\n" " " | sed -e "s/ */ /g") <<< "$TMP_BUFFER")
echo "$TMP_BUFFER" | tr -d '\n' | cb
zle redisplay
fi
}
zle -N _navi_copy_snippet
{{ if eq .chezmoi.os "darwin" -}}
bindkey '^Q^G' _navi_copy_snippet
{{ else }}
bindkey '^[Q^[G' _navi_copy_snippet
{{- end }}
# option + ↑で1つ上のディレクトリに移動
_cd-up () {
BUFFER='cd ../'
zle accept-line
}
zle -N _cd-up
bindkey '^[[1;3A' _cd-up
autoload -U modify-current-argument
# Esc + sで単語を''で囲む
_quote-previous-word-in-single() {
modify-current-argument '${(qq)${(Q)ARG}}'
zle vi-forward-blank-word
}
zle -N _quote-previous-word-in-single
bindkey '^[s' _quote-previous-word-in-single
# Esc + dで単語を""で囲む
_quote-previous-word-in-double() {
modify-current-argument '${(qqq)${(Q)ARG}}'
zle vi-forward-blank-word
}
zle -N _quote-previous-word-in-double
bindkey '^[d' _quote-previous-word-in-double
#--------------------------------------------------------------
# function
#--------------------------------------------------------------
cb() {
if command -v pbcopy &> /dev/null; then
command pbcopy
elif command -v clip.exe &> /dev/null; then
command clip.exe
fi
}
open() {
if command -v open &> /dev/null; then
command open
elif command -v xdg-open &> /dev/null; then
command xdg-open
fi
}
ssh() {
# tmux起動時
if [[ -n $(printenv TMUX) ]] ; then
# locale対応
export LC_CTYPE=en_US.UTF-8
# 接続先ホスト名に応じて背景色切り替え
if [[ `echo "$1" | grep 'audit'` ]] ; then
tmux set -p window-active-style 'bg=#400000'
tmux set -p window-style 'bg=#400000'
else
tmux set -p window-active-style 'bg=#002800'
tmux set -p window-style 'bg=#002800'
fi
command ssh $@
# 色設定を戻す
tmux set -p window-style 'bg=#303030'
tmux set -p window-active-style 'bg=#000000'
else
command ssh $@
fi
}
zsh-history-backup() {
local backup_dir="$HOME/.local/state/zsh"
while sleep $((60 * 15)) ; do
if [[ $(wc -l "$backup_dir/.zsh_history" | grep -o '[0-9]*') -gt 1000 ]] ; then
cp -u "$backup_dir/.zsh_history" "$backup_dir/zsh_history_backup_$(date '+%y%m')$(printf '%02d' $(( $(date '+%d') / 10 * 10 )))"
echo "$(date "+[%y/%m/%d %H:%M:%S]") zsh-history-backup!"
else
osascript -e 'display notification "Backup Error!" with title "zsh"'
fi
done
}
zsh-startuptime() {
local time_rc
local total_msec=0
local msec
for i in $(seq 1 10); do
msec=$((TIMEFMT='%mE'; time zsh -i -c exit) 2>/dev/stdout >/dev/null | tr -d "ms")
echo "${(l:2:)i}: ${msec} [ms]"
total_msec=$(( $total_msec + $msec ))
done
time_rc=$(( ${total_msec} / 10 ))
local time_norc
time_norc=$((TIMEFMT="%mE"; time zsh -df -i -c "autoload -Uz compinit && compinit -C; exit") &> /dev/stdout)
echo "my zshrc: ${time_rc}ms\ndefault zsh: ${time_norc}\n"
}
zsh-profiler() {
ZSHRC_PROFILE=1 zsh -i -c zprof
}
export APPDATA="/mnt/c/Users/$WINUSER/AppData"
export USERDIR="/mnt/c/Users/$WINUSER"
{{ if eq .chezmoi.os "linux" -}}
cp_winhost() {