-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.zinit.zsh
239 lines (203 loc) · 5.51 KB
/
.zinit.zsh
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
#!/usr/bin/env bash
EXCLUDE_DIRS="\
.git go/pkg virtualenvs node_modules __pycache__ cache jsm build debug release
dist dist-newstyle __MACOSX nltk_data wekafiles libchart fpdf16 _build
Documents/Pri*/* MAlonzo"
EXCLUDE_STRING=$(echo -n "$EXCLUDE_DIRS" | tr ' ' '\n' | \
sed 's/^/--exclude /' | paste -sd' ')
# fzf
FZF_BINDINGS='
# Global
esc:abort
ctrl-y:execute-silent(echo {+} | xclip)
# Navigation
ctrl-g:top
ctrl-b:half-page-up
ctrl-d:half-page-down
ctrl-k:up
ctrl-j:down
ctrl-space:jump
# Prompt
alt-h:backward-char
alt-l:forward-char
alt-b:backward-word
alt-f:forward-word
ctrl-a:beginning-of-line
ctrl-e:end-of-line
ctrl-u:unix-line-discard
ctrl-w:unix-word-rubout
# Selection
alt-c:clear-selection
alt-e:select-all
alt-t:toggle-all
tab:toggle+down
shift-tab:toggle+up
# Preview
alt-u:preview-page-up
alt-d:preview-page-down
alt-j:preview-down+preview-down+preview-down
alt-k:preview-up+preview-up+preview-up
alt-g:preview-top
alt-c:toggle-preview
# History
alt-p:previous-history
alt-n:next-history
'
FZF_BINDINGS_STRING=$(echo -n "$FZF_BINDINGS" | grep -e '^[^#]' |
tr '\n' ',' | sed -E 's/.$//')
FZF_COLORS="
dark
hl:$col_lime
fg+:$col_fg
bg+:$col_blue20
hl+:$col_lime
info:$col_fg
border:$col_fg10
prompt:$col_blue
pointer:$col_red
marker:$col_red
header:$col_fg50
gutter:-1
spinner:$col_blue
separator:$col_bg
"
FZF_COLORS_STRING="$( echo -n "$FZF_COLORS" | grep -e '^[^#]' | paste -sd',' )"
export FZF_DEFAULT_OPTS="
--exit-0 --multi --info=inline
--no-border --layout=reverse
--height 99% --no-mouse
--preview-window='down:70%:wrap'
--bind='$FZF_BINDINGS_STRING'
--color='$FZF_COLORS_STRING'
--border=none
"
# fzf-tab
zstyle ':fzf-tab:*' fzf-bindings \
"$FZF_BINDINGS_STRING"
zstyle ':fzf-tab:*' fzf-flags --height 50%
# shellcheck disable=SC2016
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'exa -1 --icons --color=always $realpath'
zstyle ':fzf-tab:complete:cd:*' fzf-flags --height 70%
FZF_DEFAULT_PREV_WIDTH=95
FZF_DEFAULT_SWITCH_LAYOUT_WIDTH=105
fzf_preview_params() {
TARGET_PREV_WIDTH="${1:-$FZF_DEFAULT_PREV_WIDTH}"
SWITCH_LAYOUT_WIDTH="${2:-$FZF_DEFAULT_SWITCH_LAYOUT_WIDTH}"
HEADER_LINES="${3:-0}"
MAX_WIDTH=$(( 3 * COLUMNS / 5 ))
PREV_WIDTH=$(( TARGET_PREV_WIDTH > MAX_WIDTH ? MAX_WIDTH : TARGET_PREV_WIDTH ))
RIGHT_PREV="right:${PREV_WIDTH}:noborder:nowrap"
HEADER_STR=$((( $HEADER_LINES != 0 )) && printf ":~%d" "$HEADER_LINES" || printf "")
if (( COLUMNS <= SWITCH_LAYOUT_WIDTH )); then
echo "up:71%:border:nowrap$HEADER_STR"
else
echo "${RIGHT_PREV}${HEADER_STR}"
fi
}
# fzf utilities
# open files
ñf() {
# No function export for zsh to clean this up :(
PREVIEW_COMMAND=$(cat <<-EOF
cat <<< $'\
\e[2mCtr-f to go to containing folder\e[0m\
'
if [[ \$(file --mime {}) =~ binary ]]; then
FILE_NAME=\$(exa --icons {} 2>/dev/null || echo {})
echo "\
\e[33;1mBinary file:\e[0m
\$FILE_NAME\
"
else
bat {} --style=numbers --color=always 2>/dev/null || cat {}
fi
EOF
)
OUT=("$(
fd --type f . $=EXCLUDE_STRING | fzf --query="$1" --preview="$PREVIEW_COMMAND" \
--preview-window="$(
fzf_preview_params \
"$FZF_DEFAULT_PREV_WIDTH" \
"$FZF_DEFAULT_SWITCH_LAYOUT_WIDTH" \
1
)" \
--expect=ctrl-f \
--history="$HOME/.fzf-open-file-history"
)")
read -r KEY <<< "$OUT"
OUT=$(tail -n +2 <<< "$OUT")
read -r FIRST <<< "$OUT"
# shellcheck disable=SC2128
if [[ -n "$OUT" ]]; then
if [[ "$KEY" == 'ctrl-f' ]]; then
cd "$(dirname "$FIRST")"
else
xargs -d'\n' "${EDITOR:-nvim}" <<< "$OUT"
fi
fi
}
# go to folder
zd() {
PREVIEW_COMMAND='exa --color always --tree --level=2 --icons --git-ignore {}'
cd "$(fd --type d . $=EXCLUDE_STRING | fzf --no-multi \
--exit-0 \
--preview="$PREVIEW_COMMAND" \
--preview-window="$(fzf_preview_params 50)" \
--history="$HOME/.fzf-zd-history")"
}
# search regex
ñg() {
FUZZY=0
if [[ "$1" =~ 'fuzzy' ]]; then
FUZZY=1
shift
fi
COMMAND_FMT='rg --column --line-number --no-heading --color=always --smart-case -- %b || true'
# shellcheck disable=SC2059
INITIAL_COMMAND=$(printf "$COMMAND_FMT" "'$1'")
# shellcheck disable=SC2059
RELOAD_COMMAND="$(printf "$COMMAND_FMT" "{q}")"
ARGS=(
--ansi
--query "$1"
'--preview=fzf_rg_preview {}'
--delimiter :
"--preview-window=$(fzf_preview_params 100 180):+{2}-/2"
"--history=$HOME/.fzf-rg-history"
)
if (( $FUZZY == 0 )); then
ARGS+=(
--disabled
--bind "change:reload:$RELOAD_COMMAND"
)
fi
RESULT=$(eval "$INITIAL_COMMAND" | fzf "${ARGS[@]}")
if [[ -n "$RESULT" ]]; then
if (( $(echo -E "$RESULT" | wc -l) > 1 )); then
${EDITOR:-nvim} -q <(echo -E "$RESULT")
else
${EDITOR:-nvim} "$(echo -E "$RESULT" | cut -d: -f1-3)"
fi
fi
}
alias ñG='ñg --fuzzy'
# forgit
export FORGIT_ADD_FZF_OPTS=$(cat <<EOF
--bind='ctrl-f:execute(printf "%s\n" {+} \
| grep -v "D\]" \
| grep -oP "\] +\K.*" \
| xargs -d"\n" bash -c "$EDITOR \\\$@ \
< /dev/tty \
> /dev/tty" _)+abort'
EOF
)
export forgit_log=gitl
export forgit_diff=gitd
export forgit_add=gita
export forgit_checkout_file=gitr
export forgit_reset_head=gitu
export forgit_ignore=gitignore
export forgit_stash_show=gitstash
# vim easymotion
bindkey -M vicmd 'ñ' vi-easy-motion
export EASY_MOTION_TARGET_KEYS='aeiousdfjl'