-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·457 lines (422 loc) · 13.5 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·457 lines (422 loc) · 13.5 KB
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
#!/usr/bin/env bash
# install.sh — one-click bootstrap and plugin management for nvide.
#
# Auto-detects Linux (Ubuntu/Debian) and macOS. Idempotent: safe to re-run.
#
# Usage:
# ./install.sh install # full bootstrap (default)
# ./install.sh update # update plugins + LeaderF + parsers + coc exts
# ./install.sh clean # remove plugins no longer declared in init.vim
# ./install.sh parsers # re-download + rebuild tree-sitter parsers only
# ./install.sh coc # (re)install coc extensions only
# ./install.sh --help
set -euo pipefail
# ---------- helpers ----------
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NVIM_MIN_VERSION="0.11"
CLANGD_MIN_VERSION="15"
COC_EXTS=(coc-snippets coc-syntax coc-word coc-pairs coc-lists coc-yank
coc-spell-checker coc-json coc-python coc-vimlsp)
if [[ -t 1 && -z "${NO_COLOR:-}" ]]; then
C_GREEN=$'\033[32m'
C_YELLOW=$'\033[33m'
C_RED=$'\033[31m'
C_BOLD=$'\033[1m'
C_RESET=$'\033[0m'
else
C_GREEN=""
C_YELLOW=""
C_RED=""
C_BOLD=""
C_RESET=""
fi
info() { printf "%s==>%s %s\n" "$C_GREEN" "$C_RESET" "$*"; }
warn() { printf "%s!!%s %s\n" "$C_YELLOW" "$C_RESET" "$*"; }
err() { printf "%sxx%s %s\n" "$C_RED" "$C_RESET" "$*" >&2; }
step() { printf "\n%s[%s]%s %s\n" "$C_BOLD" "$1" "$C_RESET" "$2"; }
detect_os() {
case "$(uname -s)" in
Linux*) echo "linux" ;;
Darwin*) echo "macos" ;;
*)
err "Unsupported OS: $(uname -s)"
exit 1
;;
esac
}
OS="$(detect_os)"
# version_ge $cur $min — true if cur >= min (dot-separated numerics)
version_ge() {
local cur="$1" min="$2"
[[ "$cur" == "$(printf '%s\n%s' "$cur" "$min" | sort -V | tail -1)" ]]
}
have() { command -v "$1" >/dev/null 2>&1; }
# Prepend known install locations to PATH so the script finds binaries even when
# the user's shell rc (which adds them) is not loaded — e.g. non-interactive shells,
# CI, or first run before PATH is configured. Idempotent (no duplicate entries).
prepend_install_dirs() {
case "$OS" in
linux)
local nv_dir="$HOME/Downloads/nvim"
if [[ -x "$nv_dir/nvim" ]] && [[ ":$PATH:" != *":$nv_dir:"* ]]; then
export PATH="$nv_dir:$PATH"
fi
local clangd_bin=""
if [[ -d "$HOME/Downloads/clangd" ]]; then
clangd_bin="$(find "$HOME/Downloads/clangd" -maxdepth 3 -type f -name clangd -path '*/bin/*' 2>/dev/null | head -1 || true)"
fi
if [[ -n "$clangd_bin" ]]; then
local clangd_dir
clangd_dir="$(dirname "$clangd_bin")"
if [[ ":$PATH:" != *":$clangd_dir:"* ]]; then
export PATH="$clangd_dir:$PATH"
fi
fi
;;
macos)
for d in /opt/homebrew/bin /opt/homebrew/opt/llvm/bin /usr/local/bin /usr/local/opt/llvm/bin; do
if [[ -d "$d" ]] && [[ ":$PATH:" != *":$d:"* ]]; then
export PATH="$d:$PATH"
fi
done
;;
esac
}
nvim_version() { nvim --version 2>/dev/null | head -1 | sed 's/^NVIM //; s/ .*//'; }
clangd_version() { clangd --version 2>/dev/null | grep -oE 'version [0-9]+\.[0-9]+' | head -1 | awk '{print $2}'; }
prepend_install_dirs
# ---------- install steps ----------
install_nvim() {
step 1 "Neovim binary (>= $NVIM_MIN_VERSION)"
local cur
cur="$(nvim_version 2>/dev/null || echo "")"
if [[ -n "$cur" ]] && version_ge "$cur" "$NVIM_MIN_VERSION"; then
info "skip: nvim $cur already in PATH"
return
fi
case "$OS" in
linux)
local dest="$HOME/Downloads/nvim"
mkdir -p "$dest"
info "downloading nvim appimage to $dest/nvim"
curl -fL -o "$dest/nvim" \
https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.appimage ||
{
rm -f "$dest/nvim"
err "download failed"
exit 1
}
chmod +x "$dest/nvim"
warn "nvim installed at $dest/nvim — add to PATH:"
warn " export PATH=\$HOME/Downloads/nvim:\$PATH"
warn "(your mydotfiles/zsh/local.ubuntu.zsh is the place if you use it)"
;;
macos)
if have brew; then
info "brew install neovim bash (bash 5+ required by download-parsers.sh)"
brew install neovim bash
else
err "Homebrew not found. Install brew or nvim manually (>= $NVIM_MIN_VERSION)."
exit 1
fi
;;
esac
}
install_clangd() {
step 2 "clangd (>= $CLANGD_MIN_VERSION, for coc.nvim C/C++ LSP)"
local cur
cur="$(clangd_version 2>/dev/null || echo "")"
if [[ -n "$cur" ]] && version_ge "$cur" "$CLANGD_MIN_VERSION"; then
info "skip: clangd $cur already in PATH"
return
fi
case "$OS" in
linux)
local dest="$HOME/Downloads/clangd"
local ver="22.1.6"
mkdir -p "$dest"
info "downloading clangd $ver to $dest"
curl -fLO --output-dir "$dest" \
"https://github.com/clangd/clangd/releases/download/$ver/clangd-linux-$ver.zip"
(cd "$dest" && unzip -o "clangd-linux-$ver.zip" >/dev/null)
warn "clangd extracted to $dest/clangd_$ver/bin/clangd — add to PATH:"
warn " export PATH=\$HOME/Downloads/clangd/clangd_$ver/bin:\$PATH"
;;
macos)
if have brew; then
info "brew install llvm (provides clangd)"
brew install llvm
warn "add brew llvm to PATH: export PATH=\$(brew --prefix llvm)/bin:\$PATH"
else
warn "Homebrew not found — install clangd manually (>= $CLANGD_MIN_VERSION)"
fi
;;
esac
}
install_neocmakelsp() {
step "2b" "neocmakelsp (for coc.nvim CMake LSP)"
local dest="$HOME/.local/bin"
if have neocmakelsp || [[ -x "$dest/neocmakelsp" ]]; then
info "skip: neocmakelsp already installed"
return
fi
mkdir -p "$dest"
local ver="0.11.0"
local arch
case "$OS" in
linux)
case "$(uname -m)" in
x86_64) arch="x86_64-unknown-linux-gnu" ;;
aarch64) arch="aarch64-unknown-linux-gnu" ;;
*) warn "unsupported linux arch $(uname -m) -- install neocmakelsp manually (cargo install neocmakelsp)"; return ;;
esac
;;
macos)
arch="universal-apple-darwin"
;;
esac
local asset="neocmakelsp-$arch.tar.gz"
local tmpdir="$HOME/.cache/nvide-neocmakelsp-$$"
mkdir -p "$tmpdir"
info "downloading neocmakelsp $ver"
if curl -fL -o "$tmpdir/$asset" "https://github.com/neocmakelsp/neocmakelsp/releases/download/v$ver/$asset"; then
tar xzf "$tmpdir/$asset" -C "$tmpdir"
install -m755 "$tmpdir/neocmakelsp" "$dest/neocmakelsp"
info "neocmakelsp installed to $dest/neocmakelsp"
else
warn "download failed -- install neocmakelsp manually (cargo install neocmakelsp or GitHub releases)"
fi
rm -rf "$tmpdir"
}
link_config() {
step 3 "Symlink ~/.config/nvim -> $REPO_DIR"
local target="$HOME/.config/nvim"
mkdir -p "$HOME/.config"
if [[ -L "$target" && "$(readlink -f "$target")" == "$REPO_DIR" ]]; then
info "skip: symlink already points to this repo"
return
fi
if [[ -e "$target" && ! -L "$target" ]]; then
local bak
bak="$target.bak.$(date +%s)"
warn "existing $target is not a symlink — backing up to $bak"
mv "$target" "$bak"
fi
ln -sfn "$REPO_DIR" "$target"
info "linked"
}
install_vimplug() {
step 4 "vim-plug"
local dest="$REPO_DIR/autoload/plug.vim"
if [[ -f "$dest" ]]; then
info "skip: plug.vim present"
return
fi
curl -fLo "$dest" --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
info "installed plug.vim"
}
install_plugins() {
step 5 "Plugins (vim-plug :PlugInstall)"
if ! have nvim; then
err "nvim not in PATH — fix PATH first (see step 1), then re-run"
exit 1
fi
# try/catch wrapper: init.vim references plugin modules after plug#end()
# that fail when plugged/ is empty on first install — harmless, suppressed here.
nvim --headless \
-c "try | silent! source $REPO_DIR/init.vim | catch | endtry" \
-c "PlugInstall" \
-c "qa!" 2>/dev/null || true
info "PlugInstall done"
}
compile_leaderf() {
step 6 "LeaderF C extension"
local lf="$REPO_DIR/plugged/LeaderF"
if [[ ! -d "$lf" ]]; then
warn "skip: LeaderF not installed yet"
return
fi
(cd "$lf" && ./install.sh >/dev/null 2>&1) || warn "LeaderF install.sh failed (non-fatal)"
info "LeaderF compiled"
}
install_ts_cli() {
step 7 "tree-sitter CLI"
local cargo_ts="$REPO_DIR/tools/cargo/bin/tree-sitter"
if [[ -x "$cargo_ts" ]]; then
info "skip: $cargo_ts present"
return
fi
if have cargo; then
info "cargo install tree-sitter-cli (builds from source, glibc-safe)"
cargo install tree-sitter-cli --root "$REPO_DIR/tools/cargo" >/dev/null 2>&1 ||
{
warn "cargo install failed, falling back to npm"
install_ts_cli_npm
}
return
fi
warn "cargo not found, using npm (may hit glibc issues on older systems)"
install_ts_cli_npm
}
install_ts_cli_npm() {
mkdir -p "$REPO_DIR/tools"
(cd "$REPO_DIR/tools" && {
[[ -f package.json ]] || npm init -y >/dev/null
npm install tree-sitter-cli >/dev/null 2>&1 || err "npm install tree-sitter-cli failed"
})
}
build_parsers() {
step 8 "tree-sitter parsers"
if [[ ! -f "$REPO_DIR/scripts/download-parsers.sh" ]]; then
err "scripts/download-parsers.sh not found"
return
fi
chmod +x "$REPO_DIR/scripts/download-parsers.sh" "$REPO_DIR/scripts/build-parsers.sh"
# download-parsers.sh uses bash 4+ associative arrays; macOS /bin/bash is 3.2,
# so use brew bash 5+ there (installed in install_nvim's macos branch).
local bash_bin="bash"
if [[ "$OS" == "macos" ]]; then
bash_bin="$(brew --prefix 2>/dev/null)/bin/bash"
[[ -x "$bash_bin" ]] || bash_bin="bash"
fi
"$bash_bin" "$REPO_DIR/scripts/download-parsers.sh"
"$bash_bin" "$REPO_DIR/scripts/build-parsers.sh"
info "parsers built"
}
install_coc_exts() {
step 9 "coc.nvim extensions"
local ext_dir="$HOME/.config/coc/extensions"
mkdir -p "$ext_dir"
(cd "$ext_dir" && {
[[ -f package.json ]] || echo '{"dependencies":{}}' >package.json
npm install "${COC_EXTS[@]}" \
--global-style --ignore-scripts --no-bin-links --no-package-lock --only=prod \
>/dev/null 2>&1 || err "coc extension install failed"
})
info "coc extensions installed: ${COC_EXTS[*]}"
}
install_yazi() {
step 10 "yazi (terminal file manager, used by tfm.nvim <Leader>t)"
if have yazi; then
info "skip: yazi already in PATH"
return
fi
if ! have cargo; then
warn "cargo not found — skipping yazi. Install Rust via rustup, then re-run (or install yazi manually)."
return
fi
# cargo-binstall fetches prebuilt binaries — far faster than building yazi from source.
if ! have cargo-binstall; then
info "installing cargo-binstall (prebuilt)"
curl -L --proto '=https' --tlsv1.2 -sSf \
https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh \
| bash >/dev/null 2>&1 || {
warn "cargo-binstall install failed — skipping yazi (non-fatal)"
return
}
fi
# Prebuilt GNU build needs GLIBC_2.39 (absent on Ubuntu 22.04); force the musl
# static build on Linux so it runs on older glibc. macOS default target is fine.
local binstall_args=(-y)
if [[ "$OS" == "linux" ]]; then
case "$(uname -m)" in
x86_64) binstall_args+=(--target x86_64-unknown-linux-musl) ;;
aarch64 | arm64) binstall_args+=(--target aarch64-unknown-linux-musl) ;;
*) warn "unrecognized arch $(uname -m) — trying default target (may need newer glibc)" ;;
esac
fi
info "cargo binstall yazi-fm yazi-cli (prebuilt)"
if cargo binstall "${binstall_args[@]}" yazi-fm yazi-cli >/dev/null 2>&1; then
info "yazi installed to ~/.cargo/bin/"
warn "ensure ~/.cargo/bin is on PATH (rustup adds it by default)"
else
warn "cargo binstall yazi failed (non-fatal) — install yazi manually"
fi
}
do_install() {
info "${C_BOLD}nvide bootstrap ($OS)${C_RESET}"
install_nvim
prepend_install_dirs
install_clangd
prepend_install_dirs
install_neocmakelsp
link_config
install_vimplug
install_plugins
compile_leaderf
install_ts_cli
build_parsers
install_coc_exts
install_yazi
step "✓" "Done. Open nvim to verify. If nvim/clangd/yazi PATH warnings appeared, add them to your shell rc and restart."
}
do_update() {
info "${C_BOLD}update plugins + LeaderF + parsers + coc${C_RESET}"
step 1 "PlugUpdate"
nvim --headless +PlugUpdate +qa 2>/dev/null || true
step 2 "Recompile LeaderF"
compile_leaderf
step 3 "Rebuild tree-sitter parsers"
build_parsers
step 4 "Update coc extensions"
local ext_dir="$HOME/.config/coc/extensions"
if [[ -d "$ext_dir" ]]; then
if ! (cd "$ext_dir" && npm update >/dev/null 2>&1); then
warn "coc npm update failed"
fi
fi
step "✓" "Update done"
}
do_clean() {
info "PlugClean — remove plugins no longer in init.vim"
nvim --headless +PlugClean +qa 2>/dev/null || true
info "done"
}
do_parsers() {
info "Rebuild tree-sitter parsers"
build_parsers
}
do_coc() {
info "(re)install coc extensions"
install_coc_exts
}
show_help() {
cat <<'EOF'
nvide install.sh — bootstrap and plugin management
Usage: ./install.sh <command>
Commands:
install Full bootstrap: nvim, clangd, config symlink, vim-plug,
plugins, LeaderF, tree-sitter, coc extensions, yazi. (default)
update Update plugins (:PlugUpdate), recompile LeaderF,
rebuild parsers, update coc extensions.
clean Remove plugins no longer declared in init.vim (:PlugClean).
parsers Re-download and rebuild tree-sitter parsers only.
coc (Re)install coc extensions only.
--help Show this help.
Interactive plugin commands inside nvim (see README for full guide):
:PlugInstall install plugins newly added to init.vim
:PlugUpdate upgrade all plugins to latest
:PlugClean remove plugins deleted from init.vim
:PlugUpgrade upgrade vim-plug itself
Notes:
- Linux: nvim appimage goes to ~/Downloads/nvim/, clangd to ~/Downloads/clangd/.
Add both to PATH in your shell rc (the script prints the exact lines).
- macOS: uses Homebrew (brew install neovim llvm).
- Idempotent: re-running `install` skips steps already satisfied.
EOF
}
# ---------- dispatch ----------
case "${1:-install}" in
install) do_install ;;
update) do_update ;;
clean) do_clean ;;
parsers) do_parsers ;;
coc) do_coc ;;
--help | -h) show_help ;;
*)
err "unknown command: $1"
show_help
exit 1
;;
esac