blob: 355b0ecc30e7a0e05678e606ce76f28029bcc5f5 (
plain)
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
|
#!/usr/bin/env bash
set -eo pipefail
#Set branch to master unless specified by the user
declare -r LV_BRANCH="${LV_BRANCH:-rolling}"
declare -r LV_REMOTE="${LV_REMOTE:-lunarvim/lunarvim.git}"
declare -r INSTALL_PREFIX="${INSTALL_PREFIX:-"$HOME/.local"}"
declare -r XDG_DATA_HOME="${XDG_DATA_HOME:-"$HOME/.local/share"}"
declare -r XDG_CACHE_HOME="${XDG_CACHE_HOME:-"$HOME/.cache"}"
declare -r XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-"$HOME/.config"}"
# TODO: Use a dedicated cache directory #1256
declare -r NEOVIM_CACHE_DIR="$XDG_CACHE_HOME/nvim"
declare -r LUNARVIM_RUNTIME_DIR="${LUNARVIM_RUNTIME_DIR:-"$XDG_DATA_HOME/lunarvim"}"
declare -r LUNARVIM_CONFIG_DIR="${LUNARVIM_CONFIG_DIR:-"$XDG_CONFIG_HOME/lvim"}"
declare -a __lvim_dirs=(
"$LUNARVIM_CONFIG_DIR"
"$LUNARVIM_RUNTIME_DIR"
"$NEOVIM_CACHE_DIR" # for now this is shared with neovim
)
declare -a __npm_deps=(
"neovim"
"tree-sitter-cli"
)
declare -a __pip_deps=(
"pynvim"
)
function main() {
cat <<'EOF'
88\ 88\
88 | \__|
88 |88\ 88\ 888888$\ 888888\ 888888\ 88\ 88\ 88\ 888888\8888\
88 |88 | 88 |88 __88\ \____88\ 88 __88\\88\ 88 |88 |88 _88 _88\
88 |88 | 88 |88 | 88 | 888888$ |88 | \__|\88\88 / 88 |88 / 88 / 88 |
88 |88 | 88 |88 | 88 |88 __88 |88 | \88$ / 88 |88 | 88 | 88 |
88 |\888888 |88 | 88 |\888888$ |88 | \$ / 88 |88 | 88 | 88 |
\__| \______/ \__| \__| \_______|\__| \_/ \__|\__| \__| \__|
EOF
__add_separator "80"
echo "Detecting platform for managing any additional neovim dependencies"
detect_platform
# skip this in a Github workflow
if [ -z "$GITHUB_ACTIONS" ]; then
check_system_deps
__add_separator "80"
echo "Would you like to check lunarvim's NodeJS dependencies?"
read -p "[y]es or [n]o (default: no) : " -r answer
[ "$answer" != "${answer#[Yy]}" ] && install_nodejs_deps
echo "Would you like to check lunarvim's Python dependencies?"
read -p "[y]es or [n]o (default: no) : " -r answer
[ "$answer" != "${answer#[Yy]}" ] && install_python_deps
echo "Would you like to check lunarvim's Rust dependencies?"
read -p "[y]es or [n]o (default: no) : " -r answer
[ "$answer" != "${answer#[Yy]}" ] && install_rust_deps
__add_separator "80"
echo "Backing up old LunarVim configuration"
backup_old_config
__add_separator "80"
fi
case "$@" in
*--overwrite*)
echo "!!Warning!! -> Removing all lunarvim related config \
because of the --overwrite flag"
read -p "Would you like to continue? [y]es or [n]o : " -r answer
[ "$answer" == "${answer#[Yy]}" ] && exit 1
for dir in "${__lvim_dirs[@]}"; do
[ -d "$dir" ] && rm -rf "$dir"
done
;;
esac
if [ -e "$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim" ]; then
echo "Packer already installed"
else
install_packer
fi
__add_separator "80"
if [ -e "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" ]; then
echo "Updating LunarVim"
update_lvim
else
clone_lvim
setup_lvim
fi
__add_separator "80"
}
function detect_platform() {
OS="$(uname -s)"
case "$OS" in
Linux)
if [ -f "/etc/arch-release" ] || [ -f "/etc/artix-release" ]; then
RECOMMEND_INSTALL="sudo pacman -S"
elif [ -f "/etc/fedora-release" ] || [ -f "/etc/redhat-release" ]; then
RECOMMEND_INSTALL="sudo dnf install -y"
elif [ -f "/etc/gentoo-release" ]; then
RECOMMEND_INSTALL="emerge install -y"
else # assume debian based
RECOMMEND_INSTALL="sudo apt install -y"
fi
;;
Darwin)
RECOMMEND_INSTALL="brew install"
;;
*)
echo "OS $OS is not currently supported."
exit 1
;;
esac
}
function print_missing_dep_msg() {
echo "[ERROR]: Unable to find dependency [$1]"
echo "Please install it first and re-run the installer. Try: $RECOMMEND_INSTALL $1"
}
function check_dep() {
if ! command -v "$1" &>/dev/null; then
print_missing_dep_msg "$1"
exit 1
fi
}
function check_system_deps() {
if ! command -v git &>/dev/null; then
print_missing_dep_msg "git"
exit 1
fi
if ! command -v nvim &>/dev/null; then
print_missing_dep_msg "neovim"
exit 1
fi
}
function install_nodejs_deps() {
check_dep "npm"
echo "Installing node modules with npm.."
for dep in "${__npm_deps[@]}"; do
if ! npm ls -g "$dep" &>/dev/null; then
printf "installing %s .." "$dep"
npm install -g "$dep"
fi
done
echo "All NodeJS dependencies are succesfully installed"
}
function install_python_deps() {
echo "Verifying that pip is available.."
if ! python3 -m ensurepip &>/dev/null; then
if ! command -v pip3 &>/dev/null; then
print_missing_dep_msg "pip"
exit 1
fi
fi
echo "Installing with pip.."
for dep in "${__pip_deps[@]}"; do
pip3 install --user "$dep"
done
echo "All Python dependencies are succesfully installed"
}
function __attempt_to_install_with_cargo() {
if ! command -v cargo &>/dev/null; then
echo "Installing missing Rust dependency with cargo"
cargo install "$1"
else
echo "[WARN]: Unable to find fd. Make sure to install it to avoid any problems"
fi
}
# we try to install the missing one with cargo even though it's unlikely to be found
function install_rust_deps() {
if ! command -v fd &>/dev/null; then
__attempt_to_install_with_cargo "fd-find"
fi
if ! command -v rg &>/dev/null; then
__attempt_to_install_with_cargo "ripgrep"
fi
echo "All Rust dependencies are succesfully installed"
}
function backup_old_config() {
for dir in "${__lvim_dirs[@]}"; do
# we create an empty folder for subsequent commands \
# that require an existing directory
mkdir -p "$dir" "$dir.bak"
if command -v rsync &>/dev/null; then
rsync --archive -hh --partial --progress \
--modify-window=1 "$dir"/ "$dir.bak"
else
cp -R "$dir/*" "$dir.bak/."
fi
done
echo "Backup operation complete"
}
function install_packer() {
git clone --progress --depth 1 https://github.com/wbthomason/packer.nvim \
"$LUNARVIM_RUNTIME_DIR/site/pack/packer/start/packer.nvim"
}
function clone_lvim() {
echo "Cloning LunarVim configuration"
if ! git clone --progress --branch "$LV_BRANCH" \
--depth 1 "https://github.com/${LV_REMOTE}" "$LUNARVIM_RUNTIME_DIR/lvim"; then
echo "Failed to clone repository. Installation failed."
exit 1
fi
}
function setup_shim() {
if [ ! -d "$INSTALL_PREFIX/bin" ]; then
mkdir -p "$INSTALL_PREFIX/bin"
fi
cat >"$INSTALL_PREFIX/bin/lvim" <<EOF
#!/bin/sh
export LUNARVIM_CONFIG_DIR="\${LUNARVIM_CONFIG_DIR:-$LUNARVIM_CONFIG_DIR}"
export LUNARVIM_RUNTIME_DIR="\${LUNARVIM_RUNTIME_DIR:-$LUNARVIM_RUNTIME_DIR}"
exec nvim -u "\$LUNARVIM_RUNTIME_DIR/lvim/init.lua" "\$@"
EOF
chmod +x "$INSTALL_PREFIX/bin/lvim"
}
function setup_lvim() {
echo "Installing LunarVim shim"
setup_shim
echo "Preparing Packer setup"
cp "$LUNARVIM_RUNTIME_DIR/lvim/utils/installer/config.example-no-ts.lua" \
"$LUNARVIM_CONFIG_DIR/config.lua"
nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \
+'autocmd User PackerComplete sleep 100m | qall' \
+PackerInstall
nvim -u "$LUNARVIM_RUNTIME_DIR/lvim/init.lua" --headless \
+'autocmd User PackerComplete sleep 100m | qall' \
+PackerSync
echo "Packer setup complete"
cp "$LUNARVIM_RUNTIME_DIR/lvim/utils/installer/config.example.lua" "$LUNARVIM_CONFIG_DIR/config.lua"
echo "Thank you for installing LunarVim!!"
echo "You can start it by running: $INSTALL_PREFIX/bin/lvim"
echo "Do not forget to use a font with glyphs (icons) support [https://github.com/ryanoasis/nerd-fonts]"
}
function update_lvim() {
if ! git -C "$LUNARVIM_RUNTIME_DIR/lvim" status -uno &>/dev/null; then
git -C "$LUNARVIM_RUNTIME_DIR/lvim" pull --ff-only --progress ||
echo "Unable to guarantee data integrity while updating. Please do that manually instead." && exit 1
fi
echo "Your LunarVim installation is now up to date!"
}
function __add_separator() {
local DIV_WIDTH="$1"
printf "%${DIV_WIDTH}s\n" ' ' | tr ' ' -
}
main "$@"
|