-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
install_neovim.sh
executable file
·1778 lines (1690 loc) · 53.4 KB
/
install_neovim.sh
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
#!/usr/bin/env bash
#
# Copyright (C) 2023 Ronald Record <ronaldrecord@gmail.com>
# Copyright (C) 2022 Michael Peter <michaeljohannpeter@gmail.com>
#
# Install Neovim and all dependencies for the Neovim config at:
# https://github.com/doctorfree/nvim-lazyman
#
# shellcheck disable=SC2001,SC2016,SC2006,SC2086,SC2181,SC2129,SC2059,SC2164
DOC_HOMEBREW="https://docs.brew.sh"
BREW_EXE="brew"
HOMEBREW_HOME=
PYTHON=
SED="sed"
have_gsed=$(type -p gsed)
[ "${have_gsed}" ] && SED="gsed"
# Use a Github API token if one is set
[ "${GITHUB_TOKEN}" ] || {
[ "${GH_API_TOKEN}" ] && export GITHUB_TOKEN="${GH_API_TOKEN}"
[ "${GITHUB_TOKEN}" ] || {
[ "${GH_TOKEN}" ] && export GITHUB_TOKEN="${GH_TOKEN}"
}
}
if [ "${GITHUB_TOKEN}" ]; then
AUTH_HEADER="-H \"Authorization: Bearer ${GITHUB_TOKEN}\""
else
AUTH_HEADER=
fi
# Use TMPDIR or TEMPDIR if they are set, otherwise /tmp
TMP=
if [ "${TMPDIR}" ]; then
[ -d "${TMPDIR}" ] && TMP="${TMPDIR}"
else
[ "${TEMPDIR}" ] && [ -d "${TEMPDIR}" ] && TMP="${TEMPDIR}"
fi
[ "${TMP}" ] || TMP="/tmp"
export TMPDIR="${TMP}"
export PATH=${HOME}/.local/bin:${PATH}
abort() {
printf "\nERROR: %s\n" "$@" >&2
exit 1
}
log() {
[ "$quiet" ] || {
printf "\n\t%s" "$@"
}
}
calc_elapsed() {
FINISH_SECONDS=$(date +%s)
ELAPSECS=$((FINISH_SECONDS - START_SECONDS))
ELAPSED=$(eval "echo $(date -ud "@$ELAPSECS" +'$((%s/3600/24)) days %H hr %M min %S sec')")
}
check_prerequisites() {
if [ "${BASH_VERSION:-}" = "" ]; then
abort "Bash is required to interpret this script."
fi
[ "${BASH_VERSINFO:-0}" -ge 4 ] || install_bash=1
if [[ $EUID -eq 0 ]]; then
abort "Script must not be run as root user"
fi
}
vercomp () {
first=$1
second=$2
first=${first//[!0-9.]/}
second=${second//[!0-9.]/}
if [[ ${first} == ${second} ]]
then
return 0
fi
local IFS=.
local i ver1=(${first}) ver2=(${second})
# fill empty fields in ver1 with zeros
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
do
ver1[i]=0
done
for ((i=0; i<${#ver1[@]}; i++))
do
if [[ -z ${ver2[i]} ]]
then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if ((10#${ver1[i]} > 10#${ver2[i]}))
then
return 1
fi
if ((10#${ver1[i]} < 10#${ver2[i]}))
then
return 2
fi
done
return 0
}
get_platform() {
platform=$(uname -s)
if [ "$platform" == "Darwin" ]; then
darwin=1
use_pip=
else
if [ -f /etc/os-release ]; then
. /etc/os-release
[ "${ID}" == "debian" ] || [ "${ID_LIKE}" == "debian" ] && debian=1
[ "${ID}" == "arch" ] || [ "${ID_LIKE}" == "arch" ] && arch=1
[ "${ID}" == "alpine" ] && alpine=1
[ "${ID}" == "fedora" ] && redhat=1
[ "${ID}" == "centos" ] && redhat=1
[ "${ID}" == "opensuse" ] && suse=1
[ "${ID}" == "void" ] && void=1
[ "${alpine}" ] || [ "${arch}" ] || [ "${debian}" ] \
|| [ "${redhat}" ] || [ "${suse}" ] || [ "${void}" ] || {
echo "${ID_LIKE}" | grep debian >/dev/null && debian=1
echo "${ID_LIKE}" | grep suse >/dev/null && suse=1
echo "${ID_LIKE}" | grep void >/dev/null && void=1
}
else
if [ -f /etc/arch-release ]; then
arch=1
else
if [ "${have_apt}" ]; then
debian=1
else
if [ -f /etc/fedora-release ]; then
redhat=1
else
if [ "${have_dnf}" ] || [ "${have_yum}" ]; then
redhat=1
else
if [ "${have_zyp}" ]; then
suse=1
else
if [ "${have_xbps}" ]; then
void=1
else
if [ "${have_apk}" ]; then
alpine=1
else
printf "\nUnknown operating system distribution\n"
fi
fi
fi
fi
fi
fi
fi
fi
fi
[ "${debian}" ] && {
PKGMGR="APT"
if [ "${have_apt}" ]; then
APT="apt -q -y"
else
if [ "${have_aptget}" ]; then
APT="apt-get -q -y"
else
printf "\nCould not locate apt or apt-get"
printf "\nUsing Homebrew to install Neovim dependencies and tools\n"
native=
fi
fi
# Ubuntu disabled pip installs of Python modules in 23.04 and above
# macOS as well
have_lsb=$(type -p lsb_release)
if [ "${have_lsb}" ]; then
ubver=$(lsb_release -rs 2>/dev/null)
if [ "${ubver}" ]; then
vercomp "${ubver}" "23.04"
case $? in
0)
use_pip=
;;
1)
use_pip=
;;
2)
use_pip=1
;;
esac
else
use_pip=1
fi
else
use_pip=1
fi
}
[ "${redhat}" ] && {
if [ "${have_dnf}" ]; then
DNF="dnf --assumeyes --quiet"
PKGMGR="DNF"
else
if [ "${have_yum}" ]; then
DNF="yum --assumeyes --quiet"
PKGMGR="YUM"
else
printf "\nCould not locate dnf or yum"
printf "\nUsing Homebrew to install Neovim dependencies and tools\n"
native=
fi
fi
}
[ "${suse}" ] && {
if [ "${have_zyp}" ]; then
PKGMGR="DNF"
else
printf "\nCould not locate zypper"
printf "\nUsing Homebrew to install Neovim dependencies and tools\n"
native=
fi
}
[ "${alpine}" ] && {
if [ "${have_apk}" ]; then
PKGMGR="APK"
else
printf "\nCould not locate apk"
printf "\nUsing Homebrew to install Neovim dependencies and tools\n"
native=
fi
}
[ "${arch}" ] && {
if [ "${have_pac}" ]; then
PKGMGR="PACMAN"
else
printf "\nCould not locate pacman"
printf "\nUsing Homebrew to install Neovim dependencies and tools\n"
native=
fi
}
[ "${void}" ] && {
if [ "${have_xbps}" ]; then
PKGMGR="XBPS"
else
printf "\nCould not locate xbps-install"
printf "\nUsing Homebrew to install Neovim dependencies and tools\n"
native=
fi
}
}
# Compare two version strings [$1: version string 1 (v1), $2: version string 2 (v2)]
# Return values:
# 0: v1 == v2
# 1: v1 > v2
# 2: v1 < v2
# Based on https://stackoverflow.com/a/4025065 by Dennis Williamson
# and https://stackoverflow.com/questions/4023830/how-to-compare-two-strings-in-dot-separated-version-format-in-bash/49351294#49351294 by Github user @fonic
compare_versions() {
# Trivial v1 == v2 test based on string comparison
[[ "$1" == "$2" ]] && return 0
# Local variables
local regex="^(.*)-r([0-9]*)$" va1=() vr1=0 va2=() vr2=0 len i IFS="."
# Split version strings into arrays, extract trailing revisions
if [[ "$1" =~ ${regex} ]]; then
va1=("${BASH_REMATCH[1]}")
[[ -n "${BASH_REMATCH[2]}" ]] && vr1=${BASH_REMATCH[2]}
else
va1=("$1")
fi
if [[ "$2" =~ ${regex} ]]; then
va2=("${BASH_REMATCH[1]}")
[[ -n "${BASH_REMATCH[2]}" ]] && vr2=${BASH_REMATCH[2]}
else
va2=("$2")
fi
# Bring va1 and va2 to same length by filling empty fields with zeros
((${#va1[@]} > ${#va2[@]})) && len=${#va1[@]} || len=${#va2[@]}
for ((i = 0; i < len; ++i)); do
[[ -z "${va1[i]}" ]] && va1[i]="0"
[[ -z "${va2[i]}" ]] && va2[i]="0"
done
# Append revisions, increment length
va1+=("$vr1")
va2+=("$vr2")
len=$((len + 1))
# Compare version elements, check if v1 > v2 or v1 < v2
for ((i = 0; i < len; ++i)); do
if ((10#${va1[i]} > 10#${va2[i]})); then
return 1
elif ((10#${va1[i]} < 10#${va2[i]})); then
return 2
fi
done
# All elements are equal, thus v1 == v2
return 0
}
install_homebrew() {
if ! command -v brew >/dev/null 2>&1; then
[ "$debug" ] && START_SECONDS=$(date +%s)
log "Installing Homebrew ..."
BREW_URL="https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh"
curl -fsSL "$BREW_URL" >${TMPDIR}/brew-$$.sh
[ $? -eq 0 ] || {
rm -f ${TMPDIR}/brew-$$.sh
curl -kfsSL "$BREW_URL" >${TMPDIR}/brew-$$.sh
}
[ -f ${TMPDIR}/brew-$$.sh ] || abort "Brew install script download failed"
chmod 755 ${TMPDIR}/brew-$$.sh
NONINTERACTIVE=1 /bin/bash -c "${TMPDIR}/brew-$$.sh" >/dev/null 2>&1
rm -f ${TMPDIR}/brew-$$.sh
export HOMEBREW_NO_INSTALL_CLEANUP=1
export HOMEBREW_NO_ENV_HINTS=1
export HOMEBREW_NO_AUTO_UPDATE=1
[ "$quiet" ] || printf " done"
if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
HOMEBREW_HOME="/home/linuxbrew/.linuxbrew"
BREW_EXE="${HOMEBREW_HOME}/bin/brew"
else
if [ -x /usr/local/bin/brew ]; then
HOMEBREW_HOME="/usr/local"
BREW_EXE="${HOMEBREW_HOME}/bin/brew"
else
if [ -x /opt/homebrew/bin/brew ]; then
HOMEBREW_HOME="/opt/homebrew"
BREW_EXE="${HOMEBREW_HOME}/bin/brew"
else
abort "Homebrew brew executable could not be located"
fi
fi
fi
if [ -f "${HOME}/.bashrc" ]; then
grep "eval \"\$(${BREW_EXE} shellenv)\"" "${HOME}/.bashrc" >/dev/null || {
echo 'if [ -x XXX ]; then' | ${SED} -e "s%XXX%${BREW_EXE}%" >>"${HOME}/.bashrc"
echo ' eval "$(XXX shellenv)"' | ${SED} -e "s%XXX%${BREW_EXE}%" >>"${HOME}/.bashrc"
echo 'fi' >>"${HOME}/.bashrc"
}
else
echo 'if [ -x XXX ]; then' | ${SED} -e "s%XXX%${BREW_EXE}%" >"${HOME}/.bashrc"
echo ' eval "$(XXX shellenv)"' | ${SED} -e "s%XXX%${BREW_EXE}%" >>"${HOME}/.bashrc"
echo 'fi' >>"${HOME}/.bashrc"
fi
[ -f "${HOME}/.zshrc" ] && {
grep "eval \"\$(${BREW_EXE} shellenv)\"" "${HOME}/.zshrc" >/dev/null || {
echo 'if [ -x XXX ]; then' | ${SED} -e "s%XXX%${BREW_EXE}%" >>"${HOME}/.zshrc"
echo ' eval "$(XXX shellenv)"' | ${SED} -e "s%XXX%${BREW_EXE}%" >>"${HOME}/.zshrc"
echo 'fi' >>"${HOME}/.zshrc"
}
}
[ "$debug" ] && {
calc_elapsed
printf "\nHomebrew install elapsed time = ${ELAPSED}\n"
}
log "Homebrew installed in ${HOMEBREW_HOME}"
log "See ${DOC_HOMEBREW}"
fi
eval "$("$BREW_EXE" shellenv)"
have_brew=$(type -p brew)
[ "$have_brew" ] && BREW_EXE="brew"
[ "$HOMEBREW_HOME" ] || {
brewpath=$(command -v brew)
if [ $? -eq 0 ]; then
HOMEBREW_HOME=$(dirname "$brewpath" | ${SED} -e "s%/bin$%%")
else
HOMEBREW_HOME="Unknown"
fi
}
}
brew_install() {
brewpkg="$1"
if command -v "$brewpkg" >/dev/null 2>&1; then
log "Using previously installed ${brewpkg}"
else
log "Installing ${brewpkg} ..."
[ "$debug" ] && START_SECONDS=$(date +%s)
"$BREW_EXE" install --quiet "$brewpkg" >/dev/null 2>&1
[ $? -eq 0 ] || "$BREW_EXE" link --overwrite --quiet "$brewpkg" >/dev/null 2>&1
[ "$quiet" ] || printf " done"
if [ "$debug" ]; then
calc_elapsed
printf " elapsed time = %s${ELAPSED}"
fi
fi
}
platform_install() {
platpkg="$1"
if [ "$2" ]; then
pkgname="$2"
else
pkgname="$platpkg"
fi
if command -v "$pkgname" >/dev/null 2>&1; then
log "Using previously installed ${platpkg}"
else
log "Installing ${platpkg} ..."
[ "$debug" ] && START_SECONDS=$(date +%s)
if [ "${debian}" ]; then
if [ "${APT}" ]; then
${SUDO} ${APT} install ${platpkg} >/dev/null 2>&1
else
[ "${quiet}" ] || printf "\n\t\tCannot locate apt to install. Skipping ..."
fi
else
if [ "${redhat}" ]; then
if [ "${DNF}" ]; then
${SUDO} ${DNF} install ${platpkg} >/dev/null 2>&1
else
[ "${quiet}" ] || {
printf "\n\t\tCannot locate dnf to install. Skipping ..."
}
fi
else
[ "${arch}" ] && {
if [ "${have_pac}" ]; then
${SUDO} pacman -S --noconfirm ${platpkg} >/dev/null 2>&1
else
[ "${quiet}" ] || {
printf "\n\t\tCannot locate pacman to install. Skipping ..."
}
fi
}
[ "${suse}" ] && {
if [ "${have_zyp}" ]; then
${SUDO} zypper install ${platpkg} >/dev/null 2>&1
else
[ "${quiet}" ] || {
printf "\n\t\tCannot locate zypper to install. Skipping ..."
}
fi
}
[ "${alpine}" ] && {
if [ "${have_apk}" ]; then
${SUDO} apk add ${platpkg} >/dev/null 2>&1
else
[ "${quiet}" ] || {
printf "\n\t\tCannot locate apk to install. Skipping ..."
}
fi
}
[ "${void}" ] && {
if [ "${have_xbps}" ]; then
${SUDO} xbps-install -S ${platpkg} >/dev/null 2>&1
else
[ "${quiet}" ] || {
printf "\n\t\tCannot locate xbps-install to install. Skipping ..."
}
fi
}
fi
fi
[ "$quiet" ] || printf " done"
if [ "$debug" ]; then
calc_elapsed
printf " elapsed time = %s${ELAPSED}"
fi
fi
}
plat_install() {
if [ "${use_homebrew}" ]; then
brew_install "$1"
else
platform_install "$1"
fi
}
install_neovim_dependencies() {
[ "$quiet" ] || printf "\nInstalling dependencies"
[ "$install_bash" ] && {
log "Installing a modern version of bash ..."
[ "$debug" ] && START_SECONDS=$(date +%s)
if [ "${use_homebrew}" ]; then
"$BREW_EXE" install --quiet bash >/dev/null 2>&1
[ $? -eq 0 ] || "$BREW_EXE" link --overwrite --quiet bash >/dev/null 2>&1
else
platform_install bash xxxfoobaryyy
fi
if [ "$debug" ]; then
calc_elapsed
printf " elapsed time = %s${ELAPSED}"
fi
}
PKGS="git curl jq tar unzip wget xclip g++"
for pkg in $PKGS
do
plat_install "$pkg"
done
install_fzf
if [ "${use_homebrew}" ]; then
brew_install clipboard
brew_install gpatch
brew_install gnu-sed
have_gsed=$(type -p gsed)
[ "${have_gsed}" ] && SED="gsed"
else
platform_install wl-clipboard wl-copy
fi
have_curl=$(type -p curl)
[ "$have_curl" ] || abort "The curl command could not be located."
have_jq=$(type -p jq)
have_wget=$(type -p wget)
if command -v gh >/dev/null 2>&1; then
log "Using previously installed gh"
else
if [ "${use_homebrew}" ]; then
# Things are so much easier with Homebrew
brew_install gh
else
OWNER=cli
PROJECT=cli
API_URL="https://api.github.com/repos/${OWNER}/${PROJECT}/releases/latest"
DL_URL=
if [[ $architecture =~ "arm" || $architecture =~ "aarch64" ]]; then
larch="arm64"
else
larch="amd64"
fi
[ "${have_curl}" ] && [ "${have_jq}" ] && {
DL_URL=$(curl --silent ${AUTH_HEADER} "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "linux_${larch}\.tar\.gz$")
}
[ "${DL_URL}" ] && {
[ "${have_wget}" ] && {
log "Installing gh ..."
TEMP_TGZ="$(mktemp --suffix=.tgz)"
wget --quiet -O "${TEMP_TGZ}" "${DL_URL}" >/dev/null 2>&1
chmod 644 "${TEMP_TGZ}"
mkdir -p ${TMPDIR}/ghit$$
tar -C ${TMPDIR}/ghit$$ -xzf "${TEMP_TGZ}"
for ghimbin in ${TMPDIR}/"ghit$$"/*/bin/gh ${TMPDIR}/"ghit$$"/bin/gh
do
[ "${ghimbin}" == "${TMPDIR}/ghit$$/*/bin/gh" ] && continue
[ -f "${ghimbin}" ] && {
ghimdir=$(dirname ${ghimbin})
ghimdir=$(dirname ${ghimdir})
tar -C ${ghimdir} -cf ${TMPDIR}/ghim-$$.tar bin share
tar -C ${HOME}/.local -xf ${TMPDIR}/ghim-$$.tar
[ -f ${HOME}/.local/bin/gh ] && chmod 755 ${HOME}/.local/bin/gh
break
}
done
rm -f "${TEMP_TGZ}"
rm -f "${TMPDIR}/ghim-$$.tar"
rm -rf ${TMPDIR}/ghit$$
[ "$quiet" ] || printf " done"
}
}
fi
fi
if command -v lazygit >/dev/null 2>&1; then
log "Using previously installed lazygit"
else
if [ "${use_homebrew}" ]; then
# Things are so much easier with Homebrew
brew_install lazygit
else
if [[ $architecture =~ "arm" || $architecture =~ "aarch64" ]]; then
larch="arm64"
else
larch="x86_64"
fi
OWNER=jesseduffield
PROJECT=lazygit
API_URL="https://api.github.com/repos/${OWNER}/${PROJECT}/releases/latest"
DL_URL=
[ "${have_curl}" ] && [ "${have_jq}" ] && {
DL_URL=$(curl --silent ${AUTH_HEADER} "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "Linux_${larch}\.tar\.gz$")
}
[ "${DL_URL}" ] && {
[ "${have_wget}" ] && {
log "Installing lazygit ..."
TEMP_TGZ="$(mktemp --suffix=.tgz)"
wget --quiet -O "${TEMP_TGZ}" "${DL_URL}" >/dev/null 2>&1
chmod 644 "${TEMP_TGZ}"
mkdir -p ${TMPDIR}/lgit$$
tar -C ${TMPDIR}/lgit$$ -xzf "${TEMP_TGZ}"
[ -f ${TMPDIR}/lgit$$/lazygit ] && {
cp ${TMPDIR}/lgit$$/lazygit ${HOME}/.local/bin/lazygit
chmod 755 ${HOME}/.local/bin/lazygit
}
rm -f "${TEMP_TGZ}"
rm -rf ${TMPDIR}/lgit$$
[ "$quiet" ] || printf " done"
}
}
fi
fi
if command -v lua-language-server >/dev/null 2>&1; then
log "Using previously installed lua-language-server"
else
if [ "${use_homebrew}" ]; then
brew_install lua-language-server
else
if [ -d ${HOME}/.local/share/lua-language-server ]
then
log "Existing ~/.local/share/lua-language-server. Skipping installation of lua-language-server"
else
if [[ $architecture =~ "arm" || $architecture =~ "aarch64" ]]; then
larch="arm64"
else
larch="x64"
fi
OWNER=LuaLS
PROJECT=lua-language-server
API_URL="https://api.github.com/repos/${OWNER}/${PROJECT}/releases/latest"
DL_URL=
[ "${have_curl}" ] && [ "${have_jq}" ] && {
DL_URL=$(curl --silent ${AUTH_HEADER} "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "linux-${larch}\.tar\.gz$")
}
[ "${DL_URL}" ] && {
[ "${have_wget}" ] && {
log "Installing lua-language-server ..."
TEMP_TGZ="$(mktemp --suffix=.tgz)"
wget --quiet -O "${TEMP_TGZ}" "${DL_URL}" >/dev/null 2>&1
chmod 644 "${TEMP_TGZ}"
mkdir -p ${TMPDIR}/lual$$
tar -C ${TMPDIR}/lual$$ -xzf "${TEMP_TGZ}"
cp -a ${TMPDIR}/lual$$ ${HOME}/.local/share/lua-language-server
chmod 755 ${HOME}/.local/share/lua-language-server/bin/lua-language-server
[ -f "${HOME}/.local/bin/lua-language-server" ] || {
echo '#!/usr/bin/env bash' > "${HOME}/.local/bin/lua-language-server"
echo 'exec "${HOME}/.local/share/lua-language-server/bin/lua-language-server" "$@"' >> "${HOME}/.local/bin/lua-language-server"
chmod 755 "${HOME}/.local/bin/lua-language-server"
}
rm -f "${TEMP_TGZ}"
rm -rf ${TMPDIR}/lual$$
[ "$quiet" ] || printf " done"
}
}
fi
fi
fi
if command -v zoxide >/dev/null 2>&1; then
log "Using previously installed zoxide"
else
log "Installing zoxide ..."
ZOXI_URL="https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh"
curl -fsSL "${ZOXI_URL}" >${TMPDIR}/zoxi-$$.sh
[ $? -eq 0 ] || {
rm -f ${TMPDIR}/zoxi-$$.sh
curl -kfsSL "${ZOXI_URL}" >${TMPDIR}/zoxi-$$.sh
}
[ -f ${TMPDIR}/zoxi-$$.sh ] && bash ${TMPDIR}/zoxi-$$.sh >/dev/null 2>&1
rm -f ${TMPDIR}/zoxi-$$.sh
if [ -f "${HOME}/.bashrc" ]; then
grep "eval \"\$(zoxide init" "${HOME}/.bashrc" >/dev/null || {
echo 'if command -v zoxide > /dev/null; then' >>"${HOME}/.bashrc"
echo ' eval "$(zoxide init bash)"' >>"${HOME}/.bashrc"
echo 'fi' >>"${HOME}/.bashrc"
}
else
echo 'if command -v zoxide > /dev/null; then' >"${HOME}/.bashrc"
echo ' eval "$(zoxide init bash)"' >>"${HOME}/.bashrc"
echo 'fi' >>"${HOME}/.bashrc"
fi
[ -f "${HOME}/.zshrc" ] && {
grep "eval \"\$(zoxide init" "${HOME}/.zshrc" >/dev/null || {
echo 'if command -v zoxide > /dev/null; then' >>"${HOME}/.zshrc"
echo ' eval "$(zoxide init zsh)"' >>"${HOME}/.zshrc"
echo 'fi' >>"${HOME}/.zshrc"
}
}
[ "$quiet" ] || printf " done"
fi
if command -v rg >/dev/null 2>&1; then
log "Using previously installed ripgrep"
else
plat_install ripgrep
fi
[ "$quiet" ] || printf "\n"
}
install_neovim() {
log "Installing Neovim ..."
OWNER=neovim
PROJECT=neovim
API_URL="https://api.github.com/repos/${OWNER}/${PROJECT}/releases/latest"
DL_URL=
if [ "$debug" ]; then
START_SECONDS=$(date +%s)
if [ "${use_homebrew}" ]; then
"$BREW_EXE" link -q libuv
"$BREW_EXE" install neovim
else
[ -d $HOME/.local ] || mkdir -p $HOME/.local
[ "${have_curl}" ] && [ "${have_jq}" ] && {
DL_URL=$(curl --silent ${AUTH_HEADER} "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "linux64\.tar\.gz$")
}
[ "${DL_URL}" ] && {
[ "${have_wget}" ] && {
TEMP_TGZ="$(mktemp --suffix=.tgz)"
wget --quiet -O "${TEMP_TGZ}" "${DL_URL}"
chmod 644 "${TEMP_TGZ}"
mkdir -p ${TMPDIR}/nvim$$
tar -C ${TMPDIR}/nvim$$ -xzf "${TEMP_TGZ}"
if [ -f ${TMPDIR}/nvim$$/nvim-linux64/bin/nvim ]; then
tar -C ${TMPDIR}/nvim$$/nvim-linux64 -cf ${TMPDIR}/nvim-$$.tar .
tar -C ${HOME}/.local -xf ${TMPDIR}/nvim-$$.tar
chmod 755 ${HOME}/.local/bin/nvim
else
for nvimbin in ${TMPDIR}/"nvim$$"/*/bin/nvim ${TMPDIR}/"nvim$$"/bin/nvim
do
[ "${nvimbin}" == "${TMPDIR}/nvim$$/*/bin/nvim" ] && continue
[ -f "${nvimbin}" ] && {
nvimdir=$(dirname ${nvimbin})
nvimdir=$(dirname ${nvimdir})
tar -C ${nvimdir} -cf ${TMPDIR}/nvim-$$.tar .
tar -C ${HOME}/.local -xf ${TMPDIR}/nvim-$$.tar
chmod 755 ${HOME}/.local/bin/nvim
break
}
done
fi
rm -f "${TEMP_TGZ}"
rm -f ${TMPDIR}/nvim-$$.tar
rm -rf ${TMPDIR}/nvim$$
}
}
fi
else
if [ "${use_homebrew}" ]; then
"$BREW_EXE" link -q libuv >/dev/null 2>&1
"$BREW_EXE" install -q neovim >/dev/null 2>&1
else
[ -d $HOME/.local ] || mkdir -p $HOME/.local
[ "${have_curl}" ] && [ "${have_jq}" ] && {
DL_URL=$(curl --silent "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "linux64\.tar\.gz$")
}
[ "${DL_URL}" ] && {
[ "${have_wget}" ] && {
TEMP_TGZ="$(mktemp --suffix=.tgz)"
wget --quiet -O "${TEMP_TGZ}" "${DL_URL}" >/dev/null 2>&1
chmod 644 "${TEMP_TGZ}"
mkdir -p ${TMPDIR}/nvim$$
tar -C ${TMPDIR}/nvim$$ -xzf "${TEMP_TGZ}"
if [ -f ${TMPDIR}/nvim$$/nvim-linux64/bin/nvim ]; then
tar -C ${TMPDIR}/nvim$$/nvim-linux64 -cf ${TMPDIR}/nvim-$$.tar .
tar -C ${HOME}/.local -xf ${TMPDIR}/nvim-$$.tar
chmod 755 ${HOME}/.local/bin/nvim
else
for nvimbin in ${TMPDIR}/"nvim$$"/*/bin/nvim ${TMPDIR}/"nvim$$"/bin/nvim; do
[ "${nvimbin}" == "${TMPDIR}/nvim$$/*/bin/nvim" ] && continue
[ -f "${nvimbin}" ] && {
nvimdir=$(dirname ${nvimbin})
nvimdir=$(dirname ${nvimdir})
tar -C ${nvimdir} -cf ${TMPDIR}/nvim-$$.tar .
tar -C ${HOME}/.local -xf ${TMPDIR}/nvim-$$.tar
chmod 755 ${HOME}/.local/bin/nvim
break
}
done
fi
rm -f "${TEMP_TGZ}"
rm -f ${TMPDIR}/nvim-$$.tar
rm -rf ${TMPDIR}/nvim$$
}
}
fi
fi
[ "$quiet" ] || printf " done"
if [ "$debug" ]; then
calc_elapsed
printf "\nInstall Neovim elapsed time = %s${ELAPSED}\n"
fi
}
install_neovim_head() {
[ "${use_homebrew}" ] && "$BREW_EXE" link -q libuv >/dev/null 2>&1
log "Building and installing nightly Neovim ..."
if [ "$debug" ]; then
START_SECONDS=$(date +%s)
if [ "${use_homebrew}" ]; then
"$BREW_EXE" install --HEAD neovim
else
[ -d ${TMPDIR}/neovim$$ ] && rm -rf ${TMPDIR}/neovim$$
git clone https://github.com/neovim/neovim.git ${TMPDIR}/neovim$$
cd ${TMPDIR}/neovim$$
rm -f ${HOME}/.local/bin/nvim
rm -rf ${HOME}/.local/share/nvim
make CMAKE_BUILD_TYPE=Release \
CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX=${HOME}/.local"
make install
cd
rm -rf ${TMPDIR}/neovim$$
fi
else
if [ "${use_homebrew}" ]; then
"$BREW_EXE" install -q --HEAD neovim >/dev/null 2>&1
else
[ -d ${TMPDIR}/neovim$$ ] && rm -rf ${TMPDIR}/neovim$$
git clone https://github.com/neovim/neovim.git ${TMPDIR}/neovim$$ >/dev/null 2>&1
cd ${TMPDIR}/neovim$$
rm -f ${HOME}/.local/bin/nvim
rm -rf ${HOME}/.local/share/nvim
make CMAKE_BUILD_TYPE=Release \
CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX=${HOME}/.local" >/dev/null 2>&1
make install >/dev/null 2>&1
cd
rm -rf ${TMPDIR}/neovim$$
fi
fi
if [ "$debug" ]; then
calc_elapsed
printf "\nInstall Neovim elapsed time = %s${ELAPSED}\n"
fi
[ "$quiet" ] || printf " done"
}
check_python() {
brew_path=$(command -v brew)
[ "${brew_path}" ] || {
[ "${BREW_EXE}" == "brew" ] || {
[ "${BREW_EXE}" ] && brew_path="${BREW_EXE}"
}
}
[ "${brew_path}" ] || {
[ "$HOMEBREW_HOME" == "Unknown" ] || {
[ "$HOMEBREW_HOME" ] && brew_path="${HOMEBREW_HOME}/bin/brew"
}
[ "${brew_path}" ] || {
if [ -x /home/linuxbrew/.linuxbrew/bin/brew ]; then
HOMEBREW_HOME="/home/linuxbrew/.linuxbrew"
brew_path="${HOMEBREW_HOME}/bin/brew"
else
if [ -x /usr/local/bin/brew ]; then
HOMEBREW_HOME="/usr/local"
brew_path="${HOMEBREW_HOME}/bin/brew"
else
if [ -x /opt/homebrew/bin/brew ]; then
HOMEBREW_HOME="/opt/homebrew"
brew_path="${HOMEBREW_HOME}/bin/brew"
fi
fi
fi
}
}
brew_dir=$(dirname "$brew_path")
if [ -x ${brew_dir}/python3 ]; then
PYTHON="${brew_dir}/python3"
else
PYTHON=$(command -v python3)
fi
}
check_ruby() {
brew_path=$(command -v brew)
brew_dir=$(dirname "$brew_path")
if [ -x "$brew_dir"/ruby ]; then
RUBY="${brew_dir}/ruby"
else
RUBY=$(command -v ruby)
fi
if [ -x "$brew_dir"/gem ]; then
GEM="${brew_dir}/gem"
else
GEM=$(command -v gem)
fi
}
# Brew doesn't create a python symlink so we do so here
link_python() {
python3_path=$(command -v python3)
[ "$python3_path" ] && {
python_dir=$(dirname "$python3_path")
if [ -w "$python_dir" ]; then
rm -f "$python_dir"/python
ln -s "$python_dir"/python3 "$python_dir"/python
fi
}
}
install_extra() {
[ "$quiet" ] || printf "\nInstalling extra language servers and tools"
for pkg in luarocks julia php composer
do
plat_install ${pkg}
done
if command -v lemonade >/dev/null 2>&1; then
log "Using previously installed lemonade"
else
[ "${darwin}" ] || {
if [ -x ${HOME}/.local/bin/lemonade ]
then
log "Existing ~/.local/bin/lemonade. Skipping installation of lemonade."
else
[[ $architecture =~ "arm" || $architecture =~ "aarch64" ]] || {
OWNER=lemonade-command
PROJECT=lemonade
API_URL="https://api.github.com/repos/${OWNER}/${PROJECT}/releases/latest"
DL_URL=
[ "${have_curl}" ] && [ "${have_jq}" ] && {
DL_URL=$(curl --silent ${AUTH_HEADER} "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "linux_amd64\.tar\.gz$")
}
[ "${DL_URL}" ] && {
[ "${have_wget}" ] && {
log "Installing lemonade ..."
TEMP_TGZ="$(mktemp --suffix=.tgz)"
wget --quiet -O "${TEMP_TGZ}" "${DL_URL}" >/dev/null 2>&1
chmod 644 "${TEMP_TGZ}"
mkdir -p ${TMPDIR}/lmnd$$
tar -C ${TMPDIR}/lmnd$$ -xzf "${TEMP_TGZ}"
[ -f ${TMPDIR}/lmnd$$/lemonade ] && {
cp ${TMPDIR}/lmnd$$/lemonade ${HOME}/.local/bin/lemonade
chmod 755 ${HOME}/.local/bin/lemonade
}
rm -f "${TEMP_TGZ}"
rm -rf ${TMPDIR}/lmnd$$
[ "$quiet" ] || printf " done"
}
}
}
fi
}
fi
have_check=$(type -p luacheck)
[ "${have_check}" ] || {
have_rocks=$(type -p luarocks)
[ "${have_rocks}" ] && {
luarocks --local install luacheck > /dev/null 2>&1
}
}
printf "\nAdding luarocks bin to PATH in shell initialization file(s)"
if [ -f "${HOME}/.bashrc" ]; then
grep "luarocks/bin" "${HOME}/.bashrc" >/dev/null || {
echo '# Luarocks bin path' >>"${HOME}/.bashrc"
echo '[ -d ${HOME}/.luarocks/bin ] && {' >>"${HOME}/.bashrc"
echo ' export PATH="${HOME}/.luarocks/bin${PATH:+:${PATH}}"' >>"${HOME}/.bashrc"
echo '}' >>"${HOME}/.bashrc"
}
else
echo '# Luarocks bin path' >"${HOME}/.bashrc"
echo '[ -d ${HOME}/.luarocks/bin ] && {' >>"${HOME}/.bashrc"
echo ' export PATH="${HOME}/.luarocks/bin${PATH:+:${PATH}}"' >>"${HOME}/.bashrc"
echo '}' >>"${HOME}/.bashrc"
fi
[ -f "${HOME}/.zshrc" ] && {
grep "luarocks/bin" "${HOME}/.zshrc" >/dev/null || {
echo '# Luarocks bin path' >>"${HOME}/.zshrc"
echo '[ -d ${HOME}/.luarocks/bin ] && {' >>"${HOME}/.zshrc"
echo ' export PATH="${HOME}/.luarocks/bin${PATH:+:${PATH}}"' >>"${HOME}/.zshrc"
echo '}' >>"${HOME}/.zshrc"
}
}
}
install_fzf() {
if [ "${debian}" ]; then
API_URL="https://api.github.com/repos/junegunn/fzf/releases/latest"
if [[ $architecture =~ "arm" || $architecture =~ "aarch64" ]]; then
larch="arm64"
else
larch="amd64"
fi
DL_URL=
DL_URL=$(curl --silent ${AUTH_HEADER} "${API_URL}" \
| jq --raw-output '.assets | .[]?.browser_download_url' \
| grep "linux_${larch}\.tar\.gz")
[ "${DL_URL}" ] && {
TEMP_TGZ="$(mktemp --suffix=.tgz)"