From a64c7874461ba98c2887619454a209e83e0104d5 Mon Sep 17 00:00:00 2001 From: Robert Morrison Date: Fri, 10 Apr 2026 02:13:31 +0100 Subject: [PATCH] feat(lazy): Add more checks to init I have extra checks in the lazy init/bootstrap process for my own sanity. These just make sure git is actually installed, and you have internet. --- lua/plugins/lazy/init.lua | 68 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/lua/plugins/lazy/init.lua b/lua/plugins/lazy/init.lua index 299852f..ef80ad5 100644 --- a/lua/plugins/lazy/init.lua +++ b/lua/plugins/lazy/init.lua @@ -1,23 +1,89 @@ +-- Boostrap Lazy plugin manager local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" + +-- It is possible to install this config via tarball, +-- or inherit it when copying my user config to a new machine. +-- +-- It is also possible that git can be installed but not in $PATH +-- especially when linux DE's are started via `exec env` +-- +-- as such the system installing it may not have git avaialable +-- This is a failure condition as we cannot bootstrap, +-- nor manage plugins without it. +if vim.fn.executable("git") == 0 then + vim.api.nvim_echo( + { + { "git is not installed, will be unable to use Lazy\n", "ErrorMsg"}, + { "your PATH is: ", "WarningMsg" }, + { vim.env.PATH, "WarningMsg"}, -- output path for debugging purposes + { "\nPress any key to exit..."} + }, true, {} ) + vim.fn.getchar() + os.exit(1) +end + + +-- Standard bootstrapping process. if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" + + local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, { out, "WarningMsg" }, { "\nPress any key to exit..." }, - }, true, {}) + }, true, {} ) vim.fn.getchar() os.exit(1) end end vim.opt.rtp:prepend(lazypath) +-- Check for internet, if we have curl.. +-- This check is intentionally placed after the bootstrapping +-- as bootstrapping will fail if we don't have internet anyway. +-- and outside of that it is not a failure condition +if vim.fn.executable("curl") == 1 then + local out = vim.fn.system({ + "curl", + "-sS" , -- only output errors + "--head", -- only get headers + "www.google.com", + "-o", -- send any output to /dev/null + "/dev/null" + }) + + if vim.v.shell_error ~= 0 then + vim.api.nvim_echo({ + { "We can't connect to the internet\n", "WarningMsg"}, + { "This is what curl said: ", "WarningMsg" }, + { out, "WarningMsg" }, + { "Packages can load, but we cannot install/update\n" }, + { "Press any key to continue...\n" } + }, true, {}) + end +end + +-- Actually load Lazy and get it going require("lazy").setup({ spec = { { import = "plugins.spec" }, }, checker = { enabled = true }, + + performance = { + rtp = { + disabled_plugins ={ + "netrwPlugin", + "gzip", + "tarPlugin", + "tohtml", + "tutor", + "zipPlugin" + } + } + } })