-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzshrc_custom
158 lines (136 loc) · 5.41 KB
/
zshrc_custom
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
alias vi=nvim
alias lg=lazygit
alias gf="git flow"
alias cat="bat"
alias tcap='tmux capture-pane -p -S - -E -'
bindkey "^R" history-incremental-search-backward
export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$HOME/.local/bin:$PATH"
export EDITOR=nvim
export XDG_CONFIG_HOME="$HOME/.config"
#export KIND_EXPERIMENTAL_PROVIDER=podman
# ---- FZF -----
# Set up fzf key bindings and fuzzy completion
eval "$(fzf --zsh)"
# --- setup fzf theme ---
fg="#CBE0F0"
bg="#011628"
bg_highlight="#143652"
purple="#B388FF"
blue="#06BCE4"
cyan="#2CF9ED"
export FZF_DEFAULT_OPTS="--layout=reverse --tmux center,80%,60% --color=fg:${fg},bg:${bg},hl:${purple},fg+:${fg},bg+:${bg_highlight},hl+:${purple},info:${blue},prompt:${cyan},pointer:${cyan},marker:${cyan},spinner:${cyan},header:${cyan}"
# -- Use fd instead of fzf --
export FZF_DEFAULT_COMMAND="fd --hidden --strip-cwd-prefix --exclude .git"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type=d --hidden --strip-cwd-prefix --exclude .git"
# Use fd (https://github.com/sharkdp/fd) for listing path candidates.
# - The first argument to the function ($1) is the base path to start traversal
# - See the source code (completion.{bash,zsh}) for the details.
_fzf_compgen_path() {
fd --hidden --exclude .git . "$1"
}
# Use fd to generate the list for directory completion
_fzf_compgen_dir() {
fd --type=d --hidden --exclude .git . "$1"
}
show_file_or_dir_preview="if [ -d {} ]; then eza --tree --color=always {} | head -200; else bat -n --color=always --line-range :500 {}; fi"
export FZF_CTRL_T_OPTS="--preview '$show_file_or_dir_preview'"
export FZF_CTRL_R_OPTS=""
export FZF_ALT_C_OPTS="--preview 'eza --tree --color=always {} | head -200'"
# Use ~~ as the trigger sequence instead of the default **
# export FZF_COMPLETION_TRIGGER='~~'
# Advanced customization of fzf options via _fzf_comprun function
# - The first argument to the function is the name of the command.
# - You should make sure to pass the rest of the arguments to fzf.
# e.g.
# vi **<tab>
# cd **<tab>
_fzf_comprun() {
local command=$1
shift
case "$command" in
vi) fzf --preview "$show_file_or_dir_preview" "$@" ;;
cd) fzf --preview 'eza --tree --color=always {} | head -200' "$@" ;;
export|unset) fzf --preview "eval 'echo \${}'" "$@" ;;
ssh) fzf --preview 'dig {}' "$@" ;;
git) (git branch 2>/dev/null || return 1) | sed 's/[\* ]*//g' | fzf --preview 'git show {}' ;;
*) fzf --preview "$show_file_or_dir_preview" "$@" ;;
esac
}
# ----- Bat (better cat) -----
export BAT_THEME=tokyonight_night
# ---- Eza (better ls) -----
alias ls="eza -l --git"
export EZA_ICONS_AUTO=always
# ---- vim switch ----
sv(){
vim=$1
case $vim in
lazy*)
echo "Switch to LazyVim"
mkdir -p ~/.local/{share,state}/nvim.{astronvim,lazyvim} ~/.cache/nvim.{astronvim,lazyvim}
rm -f ~/.config/nvim ~/.local/state/nvim ~/.local/share/nvim ~/.cache/nvim
ln -sf ~/.config/dotfiles/nvim.lazyvim ~/.config/nvim
ln -sf ~/.local/share/nvim.lazyvim ~/.local/share/nvim
ln -sf ~/.local/state/nvim.lazyvim ~/.local/state/nvim
ln -sf ~/.cache/nvim.lazyvim ~/.cache/nvim
;;
astro*)
echo "Switch to AstroNvim"
mkdir -p ~/.local/{share,state}/nvim.{astronvim,lazyvim} ~/.cache/nvim.{astronvim,lazyvim}
rm -f ~/.config/nvim ~/.local/state/nvim ~/.local/share/nvim ~/.cache/nvim
ln -sf ~/.config/dotfiles/nvim.astronvim ~/.config/nvim
ln -sf ~/.local/share/nvim.astronvim ~/.local/share/nvim
ln -sf ~/.local/state/nvim.astronvim ~/.local/state/nvim
ln -sf ~/.cache/nvim.astronvim ~/.cache/nvim
;;
nvchad)
echo "Switch to NvChad"
mkdir -p ~/.local/{share,state}/nvim.{astronvim,lazyvim,nvchad} ~/.cache/nvim.{astronvim,lazyvim,nvchad}
rm -f ~/.config/nvim ~/.local/state/nvim ~/.local/share/nvim ~/.cache/nvim
ln -sf ~/.config/dotfiles/nvim.nvchad ~/.config/nvim
ln -sf ~/.local/share/nvim.nvchad ~/.local/share/nvim
ln -sf ~/.local/state/nvim.nvchad ~/.local/state/nvim
ln -sf ~/.cache/nvim.nvchad ~/.cache/nvim
;;
*)
echo "Current nvim: $(ls -ld ~/.config/nvim|awk -F. '{print $NF}')"
;;
esac
}
# ---- fzf-git ----
if [ -f ~/.local/bin/fzf-git.sh ];then
source ~/.local/bin/fzf-git.sh
fi
# ---- fzf-tab ----
if [ -f ~/.local/bin/fzf-zsh-completion.sh ];then
source ~/.local/bin/fzf-zsh-completion.sh
fi
# ---- ripgrep fzf view ----
rfv(){
rg --color=always --line-number --no-heading --smart-case "${*:-}" 2>/dev/null|
fzf --ansi \
--delimiter : \
--preview 'bat --color=always {1} --highlight-line {2}' \
--bind 'enter:become(nvim {1} +{2})'
}
zle -N rfv
bindkey -M vicmd '^F^G' rfv
bindkey -M viins '^F^G' rfv
# ---- fd fzf view ----
ffv(){
fd --hidden --strip-cwd-prefix --exclude .git 2>/dev/null|
fzf --ansi \
--preview "$show_file_or_dir_preview" \
--bind 'enter:become(nvim {-1})'
}
zle -N ffv
bindkey -M vicmd '^F^F' ffv
bindkey -M viins '^F^F' ffv
zstyle ':completion:*' fzf-search-display true
zstyle ':completion:*' fzf-completion-secondary-color red
zstyle ':completion::*:(cd|eza)::*' fzf-completion-opts --preview='eval eza -l -L1 --git --tree --color=always {1}|head -200'
zstyle ':completion::*:*::*' fzf-completion-opts --preview='
eval set -- {+1}
if [ -d "$@" ]; then eza -L1 --tree -l --git --color=always "$@"| head -200; else bat -n --color=always --line-range :500 "$@"; fi
'