-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy path.lazymanrc
398 lines (392 loc) · 14.5 KB
/
.lazymanrc
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
# $HOME/.config/nvim-Lazyman/.lazymanrc
# This file should be sourced from the shell initialization file
# e.g. $HOME/.bashrc or $HOME/.zshrc
#
# Command to open a URL
# Set this to override the defaults:
# On macOS the default is the 'open' command
# Linux default is 'python3 -m webbrowser' then 'xdg-open' then 'gio open'
# export URL_OPEN_COMMAND="your custom command"
# For example, to use 'gio' rather than Python's webbrowser module on Linux:
# export URL_OPEN_COMMAND="gio open"
#
# To specify the browser, set the BROWSER environment variable. For example:
# export BROWSER="w3m"
#
# Bob neovim version manager path
[ -d ${HOME}/.local/share/bob/nvim-bin ] && {
export PATH="${HOME}/.local/share/bob/nvim-bin${PATH:+:${PATH}}"
}
# Aliases for lsd, tldr, and bat if they exist
have_lsd=
command -v lsd > /dev/null && alias ls='lsd --group-dirs first' && {
alias tree='lsd --tree' && alias lss='lsd --group-dirs first'
have_lsd=1
}
# Check fzf version for preview options to use
fzfver=0
command -v fzf > /dev/null && {
fzfver=$(fzf --version | awk -F '.' '{ print $2 }')
command -v tldr > /dev/null && {
alias tldrf='tldr --list | fzf --preview "tldr {1} --color=always" --preview-window=right:70% | xargs tldr --color=always'
}
}
command -v bat > /dev/null && alias less='bat'
command -v batcat > /dev/null && \
alias bat='batcat' && \
alias less='batcat'
# To use Vim
command -v vim > /dev/null && alias vi='vim'
# To use Neovim
command -v nvim > /dev/null && {
# For compatibility with earlier versions of .lazymanrc
if alias nvim >/dev/null 2>&1; then
unalias nvim
fi
if alias nvims >/dev/null 2>&1; then
unalias nvims
fi
if alias neovides >/dev/null 2>&1; then
unalias neovides
fi
alias vi='nvim'
# Uncomment this line to use Neovim even when you type vim
# Leave commented to use vim as a backup editor if nvim not found
# alias vim='nvim'
function set_items() {
while IFS= read -r ndir
do
[ "${ndir}" ] || continue
[ -d ${HOME}/.config/${ndir} ] && {
alias ${ndir}="NVIM_APPNAME=${ndir} nvim"
entry=$(echo ${ndir} | sed -e "s/nvim-//")
items+=("${entry}")
ndirs+=("${ndir}")
}
done < "${HOME}/.config/nvim-Lazyman/.nvimdirs"
}
items=()
ndirs=()
[ -d ${HOME}/.config/nvim ] && {
alias nvim-default="NVIM_APPNAME=nvim nvim"
}
# Add all previously installed Neovim configurations
[ -f ${HOME}/.config/nvim-Lazyman/.nvimdirs ] && set_items
function runconfig() {
cfg="$1"
shift
comm="nvim"
dash=
[ "${USE_NEOVIDE}" ] && {
comm="neovide"
dash='--'
}
[ -d "${HOME}/.config/${cfg}" ] || {
[ -d "${HOME}/.config/nvim-${cfg}" ] && cfg="nvim-${cfg}"
}
# Use a file tree explorer for configurations without a dashboard
case ${cfg} in
nvim-BasicLsp|nvim-BasicMason|nvim-Craftzdog|nvim-Enrique|nvim-Extralight|nvim-LspCmp|nvim-Minimal|nvim-Primeagen|nvim-Simple|nvim-SingleFile)
explore="Lexplore"
;;
nvim-Kabin|nvim-Lamia|nvim-Kickstart|nvim-KickstartPython|nvim-Maddison|nvim-Rafi|nvim-Slydragonn|nvim-Wuelner)
explore="Neotree"
;;
nvim-Beethoven|nvim-Cosmic|nvim-Fennel|nvim-Opinion|nvim-Optixal|nvim-Orange|nvim-Xiao)
explore="NvimTreeOpen"
;;
nvim-Basic|nvim-Cpp|nvim-Go|nvim-Kristijan|nvim-Metis|nvim-Modular|nvim-NvChad|nvim-Python|nvim-Rust|nvim-Scratch|nvim-StartLsp|nvim-StartMason|nvim-Vimacs)
explore="NvimTreeToggle"
;;
nvim-3rd)
explore='lua local api = require("nvim-tree.api") local tree = require("nvim-tree") api.tree.toggle(true)'
;;
*)
explore=
;;
esac
if (( ${#@} )); then
NVIM_APPNAME="${cfg}" ${comm} ${dash} ${srcopt} ${nvimsrc} ${cmdopt} ${nvimcmd} $@
else
if [[ "${explore}" ]]; then
NVIM_APPNAME="${cfg}" ${comm} ${dash} -c "${explore}"
else
NVIM_APPNAME="${cfg}" ${comm}
fi
fi
}
function nvims_usage() {
cmd="$1"
printf "\nUsage: ${cmd} [-c cmd] [-C fltr] [-I] [-R] [-S file] [-U] [file1 [file2] ...]"
printf "\n\t'-c cmd' : 'Ex' command to be executed after first file read"
printf "\n\t'-C fltr' : filter to use when generating the list to select from"
printf "\n\t'-I' : display the selected configuration information document"
printf "\n\t'-R' : indicates removal of the selected Neovim configuration"
printf "\n\t'-S file' : Executes 'Vimscript' or 'Lua' in 'file' after file read"
printf "\n\t\t'~/.config/nvim-Lazyman/overrides.lua' is used if not empty"
printf "\n\t'-U' : displays a usage message and exits\n"
printf "\nExamples:"
printf "\n\t${cmd}"
printf "\n\t\tOpens Neovim using the selected configuration"
printf "\n\t${cmd} main.cpp"
printf "\n\t\tOpens 'main.cpp' with Neovim using the selected configuration"
printf "\n\t${cmd} -C lazy"
printf "\n\t\tOpens Neovim using the configuration selected from those"
printf "\n\t\twith names containing the case insensitive string 'lazy'"
printf "\n\t${cmd} -I"
printf "\n\t\tDisplays information for the selected Neovim configuration"
printf "\n\t${cmd} -R"
printf "\n\t\tRemoves the selected Neovim configuration"
return
}
function nvims() {
action="Open"
info=
filter=
remove=
cmdopt=
nvimcmd=
srcopt=
nvimsrc=
overfile="${HOME}/.config/nvim-Lazyman/overrides.lua"
oversize=$(grep -v '^--' "${overfile}")
[[ -z "${oversize}" ]] || {
srcopt="-S"
nvimsrc="${overfile}"
}
local OPTIND o a
while getopts ":c:C:IRS:U" o; do
case "${o}" in
c)
cmdopt="-c"
nvimcmd="${OPTARG}"
;;
C)
filter="${OPTARG}"
;;
I)
info=1
action="View Info for"
;;
R)
remove=1
action="Remove"
;;
S)
[ -s "${OPTARG}" ] && {
srcopt="-S"
nvimsrc="${OPTARG}"
}
;;
U)
nvims_usage nvims
return
;;
\?)
printf "\nInvalid nvims option"
nvims_usage nvims
return
;;
esac
done
shift $((OPTIND-1))
if [ -f ${HOME}/.config/nvim-Lazyman/.nvimdirs ]; then
items=()
ndirs=()
set_items
fi
numitems=${#items[@]}
if [ ${numitems} -eq 1 ]; then
config="${items[@]:0:1}"
else
height=$((numitems * 6))
[ ${height} -gt 100 ] && height=100
[ ${height} -lt 20 ] && height=20
if [ "${filter}" ]; then
if [[ -z ${remove} ]]; then
if [ "${have_lsd}" ]; then
if [ ${fzfver} -ge 40 ]; then
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window 'right:border-left:50%:<40(right:border-left:50%:hidden)' --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
else
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window=right:50% --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
else
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | grep -v Lazyman | fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
else
if [ "${have_lsd}" ]; then
if [ ${fzfver} -ge 40 ]; then
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | grep -v Lazyman | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window 'right:border-left:50%:<40(right:border-left:50%:hidden)' --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
else
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | grep -v Lazyman | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window=right:50% --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
else
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | grep -v Lazyman | fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
fi
else
if [[ -z ${remove} ]]; then
if [ "${have_lsd}" ]; then
if [ ${fzfver} -ge 40 ]; then
config=$(printf "%s\n" "${items[@]}" | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window 'right:border-left:50%:<40(right:border-left:50%:hidden)' --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
else
config=$(printf "%s\n" "${items[@]}" | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window=right:50% --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
else
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
else
if [ "${have_lsd}" ]; then
if [ ${fzfver} -ge 40 ]; then
config=$(printf "%s\n" "${items[@]}" | grep -v Lazyman | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window 'right:border-left:50%:<40(right:border-left:50%:hidden)' --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
else
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | grep -v Lazyman | FZF_DEFAULT_OPTS="${FZF_DEFAULT_OPTS-} --preview-window=right:50% --preview 'lsd -l -A --tree --depth=1 --color=always --blocks=size,name ~/.config/nvim-{} | head -200'" fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
else
config=$(printf "%s\n" "${items[@]}" | grep -v Lazyman | fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
fi
fi
fi
if [[ -z ${config} ]]; then
echo "Nothing selected"
return 0
else
if [ -d ${HOME}/.config/nvim-${config} ]; then
config="nvim-${config}"
[[ -z ${remove} ]] && [[ -z ${info} ]] && {
alias vi="NVIM_APPNAME=${NVIM_APPNAME:-${config}} nvim"
}
else
[ -d ${HOME}/.config/${config} ] || {
echo "Cannot locate ${config} Neovim configuration directory"
return 0
}
fi
fi
if [[ -z ${remove} ]]; then
if [[ -z ${info} ]]; then
export USE_NEOVIDE=
runconfig "${config}" $@
else
lazyman -N "${config}" info
fi
else
[[ "${config}" == "nvim-Lazyman" ]] || lazyman -R -N ${config}
fi
}
function neovides() {
action="Open"
info=
filter=
remove=
cmdopt=
nvimcmd=
srcopt=
nvimsrc=
overfile="${HOME}/.config/nvim-Lazyman/overrides.lua"
oversize=$(grep -v '^--' "${overfile}")
[[ -z "${oversize}" ]] || {
srcopt="-S"
nvimsrc="${overfile}"
}
local OPTIND o a
while getopts ":c:C:IRS:U" o; do
case "${o}" in
c)
cmdopt="-c"
nvimcmd="${OPTARG}"
;;
C)
filter="${OPTARG}"
;;
I)
info=1
action="View Info for"
;;
R)
remove=1
action="Remove"
;;
S)
[ -s "${OPTARG}" ] && {
srcopt="-S"
nvimsrc="${OPTARG}"
}
;;
U)
nvims_usage neovides
return
;;
\?)
printf "\nInvalid neovides option"
nvims_usage neovides
return
;;
esac
done
shift $((OPTIND-1))
if [ -f ${HOME}/.config/nvim-Lazyman/.nvimdirs ]; then
items=()
ndirs=()
set_items
fi
numitems=${#items[@]}
if [ ${numitems} -eq 1 ]; then
config="${items[@]:0:1}"
else
height=$((numitems * 6))
[ ${height} -gt 100 ] && height=100
[ ${height} -lt 20 ] && height=20
if [ "${filter}" ]; then
config=$(printf "%s\n" "${items[@]}" | grep -i ${filter} | fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
else
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" ${action} Neovim Config " --height=${height}% --layout=reverse --border --exit-0)
fi
fi
if [[ -z ${config} ]]; then
echo "Nothing selected"
return 0
else
if [ -d ${HOME}/.config/nvim-${config} ]; then
config="nvim-${config}"
[[ -z ${remove} ]] && [[ -z ${info} ]] && {
alias neovide="NVIM_APPNAME=${NVIM_APPNAME:-${config}} neovide"
}
else
[ -d ${HOME}/.config/${config} ] || {
echo "Cannot locate ${config} Neovim configuration directory"
return 0
}
fi
fi
if [[ -z ${remove} ]]; then
if [[ -z ${info} ]]; then
export USE_NEOVIDE=1
runconfig "${config}" $@
else
lazyman -N "${config}" info
fi
else
[[ "${config}" == "nvim-Lazyman" ]] || lazyman -R -N ${config}
fi
}
}
# Add ~/.local/bin to PATH if it exists
[ -d $HOME/.local/bin ] && {
[[ ":$PATH:" == *":$HOME/.local/bin:"* ]] || {
export PATH="$PATH:$HOME/.local/bin"
}
}
# Add ~/.cargo/bin to PATH if it exists
[ -d $HOME/.cargo/bin ] && {
[[ ":$PATH:" == *":$HOME/.cargo/bin:"* ]] || {
export PATH="$PATH:$HOME/.cargo/bin"
}
}
# Add ~/.luarocks/bin to PATH if it exists
[ -d $HOME/.luarocks/bin ] && {
[[ ":$PATH:" == *":$HOME/.luarocks/bin:"* ]] || {
export PATH="$PATH:$HOME/.luarocks/bin"
}
}