mirror of
https://github.com/marcogll/omarchy_setup.git
synced 2026-01-13 13:25:16 +00:00
docs(v3.5.0): update README for integrated mg_dotfiles and security improvements
- Integrated mg_dotfiles as regular directory (not submodule) - Added .zshrc.local.example template for local configs without secrets - Added mg_dotfiles/zsh/.zshrc.local to .gitignore to protect API keys - Updated README to reflect mg_dotfiles integration and new structure - Added nvim configuration directory with LazyVim setup
This commit is contained in:
3
mg_dotfiles/nvim/lua/config/autocmds.lua
Normal file
3
mg_dotfiles/nvim/lua/config/autocmds.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
-- Autocmds are automatically loaded on the VeryLazy event
|
||||
-- Default autocmds that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/autocmds.lua
|
||||
-- Add any additional autocmds here
|
||||
154
mg_dotfiles/nvim/lua/config/gentleman/utils.lua
Normal file
154
mg_dotfiles/nvim/lua/config/gentleman/utils.lua
Normal file
@@ -0,0 +1,154 @@
|
||||
-- https://github.com/EmmanuelOga/columns/blob/master/utils/color.lua
|
||||
|
||||
local M = {}
|
||||
|
||||
local hexChars = "0123456789abcdef"
|
||||
|
||||
function M.hex_to_rgb(hex)
|
||||
hex = string.lower(hex)
|
||||
local ret = {}
|
||||
for i = 0, 2 do
|
||||
local char1 = string.sub(hex, i * 2 + 2, i * 2 + 2)
|
||||
local char2 = string.sub(hex, i * 2 + 3, i * 2 + 3)
|
||||
local digit1 = string.find(hexChars, char1) - 1
|
||||
local digit2 = string.find(hexChars, char2) - 1
|
||||
ret[i + 1] = (digit1 * 16 + digit2) / 255.0
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
--[[
|
||||
* Converts an RGB color value to HSL. Conversion formula
|
||||
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
||||
* Assumes r, g, and b are contained in the set [0, 255] and
|
||||
* returns h, s, and l in the set [0, 1].
|
||||
*
|
||||
* @param Number r The red color value
|
||||
* @param Number g The green color value
|
||||
* @param Number b The blue color value
|
||||
* @return Array The HSL representation
|
||||
]]
|
||||
function M.rgbToHsl(r, g, b)
|
||||
local max, min = math.max(r, g, b), math.min(r, g, b)
|
||||
local h = 0
|
||||
local s = 0
|
||||
local l = 0
|
||||
|
||||
l = (max + min) / 2
|
||||
|
||||
if max == min then
|
||||
h, s = 0, 0 -- achromatic
|
||||
else
|
||||
local d = max - min
|
||||
if l > 0.5 then
|
||||
s = d / (2 - max - min)
|
||||
else
|
||||
s = d / (max + min)
|
||||
end
|
||||
if max == r then
|
||||
h = (g - b) / d
|
||||
if g < b then
|
||||
h = h + 6
|
||||
end
|
||||
elseif max == g then
|
||||
h = (b - r) / d + 2
|
||||
elseif max == b then
|
||||
h = (r - g) / d + 4
|
||||
end
|
||||
h = h / 6
|
||||
end
|
||||
|
||||
return h * 360, s * 100, l * 100
|
||||
end
|
||||
|
||||
--[[
|
||||
* Converts an HSL color value to RGB. Conversion formula
|
||||
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
|
||||
* Assumes h, s, and l are contained in the set [0, 1] and
|
||||
* returns r, g, and b in the set [0, 255].
|
||||
*
|
||||
* @param Number h The hue
|
||||
* @param Number s The saturation
|
||||
* @param Number l The lightness
|
||||
* @return Array The RGB representation
|
||||
]]
|
||||
function M.hslToRgb(h, s, l)
|
||||
local r, g, b
|
||||
|
||||
if s == 0 then
|
||||
r, g, b = l, l, l -- achromatic
|
||||
else
|
||||
function hue2rgb(p, q, t)
|
||||
if t < 0 then
|
||||
t = t + 1
|
||||
end
|
||||
if t > 1 then
|
||||
t = t - 1
|
||||
end
|
||||
if t < 1 / 6 then
|
||||
return p + (q - p) * 6 * t
|
||||
end
|
||||
if t < 1 / 2 then
|
||||
return q
|
||||
end
|
||||
if t < 2 / 3 then
|
||||
return p + (q - p) * (2 / 3 - t) * 6
|
||||
end
|
||||
return p
|
||||
end
|
||||
|
||||
local q
|
||||
if l < 0.5 then
|
||||
q = l * (1 + s)
|
||||
else
|
||||
q = l + s - l * s
|
||||
end
|
||||
local p = 2 * l - q
|
||||
|
||||
r = hue2rgb(p, q, h + 1 / 3)
|
||||
g = hue2rgb(p, q, h)
|
||||
b = hue2rgb(p, q, h - 1 / 3)
|
||||
end
|
||||
|
||||
return r * 255, g * 255, b * 255
|
||||
end
|
||||
|
||||
function M.hexToHSL(hex)
|
||||
local hsluv = require("solarized-osaka.hsluv")
|
||||
local rgb = M.hex_to_rgb(hex)
|
||||
local h, s, l = M.rgbToHsl(rgb[1], rgb[2], rgb[3])
|
||||
|
||||
return string.format("hsl(%d, %d, %d)", math.floor(h + 0.5), math.floor(s + 0.5), math.floor(l + 0.5))
|
||||
end
|
||||
|
||||
--[[
|
||||
* Converts an HSL color value to RGB in Hex representation.
|
||||
* @param Number h The hue
|
||||
* @param Number s The saturation
|
||||
* @param Number l The lightness
|
||||
* @return String The hex representation
|
||||
]]
|
||||
function M.hslToHex(h, s, l)
|
||||
local r, g, b = M.hslToRgb(h / 360, s / 100, l / 100)
|
||||
|
||||
return string.format("#%02x%02x%02x", r, g, b)
|
||||
end
|
||||
|
||||
function M.replaceHexWithHSL()
|
||||
-- Get the current line number
|
||||
local line_number = vim.api.nvim_win_get_cursor(0)[1]
|
||||
|
||||
-- Get the line content
|
||||
local line_content = vim.api.nvim_buf_get_lines(0, line_number - 1, line_number, false)[1]
|
||||
|
||||
-- Find hex code patterns and replace them
|
||||
for hex in line_content:gmatch("#[0-9a-fA-F]+") do
|
||||
local hsl = M.hexToHSL(hex)
|
||||
line_content = line_content:gsub(hex, hsl)
|
||||
end
|
||||
|
||||
-- Set the line content back
|
||||
vim.api.nvim_buf_set_lines(0, line_number - 1, line_number, false, { line_content })
|
||||
end
|
||||
|
||||
return M
|
||||
163
mg_dotfiles/nvim/lua/config/keymaps.lua
Normal file
163
mg_dotfiles/nvim/lua/config/keymaps.lua
Normal file
@@ -0,0 +1,163 @@
|
||||
-- This file contains custom key mappings for Neovim.
|
||||
|
||||
-- Keymaps are automatically loaded on the VeryLazy event
|
||||
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
|
||||
-- Add any additional keymaps here
|
||||
|
||||
-- Map Ctrl+b in insert mode to delete to the end of the word without leaving insert mode
|
||||
vim.keymap.set("i", "<C-b>", "<C-o>de")
|
||||
|
||||
-- Map Ctrl+c to escape from other modes
|
||||
vim.keymap.set({ "i", "n", "v" }, "<C-c>", [[<C-\><C-n>]])
|
||||
|
||||
-- Screen Keys
|
||||
vim.keymap.set({ "n" }, "<leader>uk", "<cmd>Screenkey<CR>")
|
||||
|
||||
----- Tmux Navigation ------
|
||||
local nvim_tmux_nav = require("nvim-tmux-navigation")
|
||||
|
||||
vim.keymap.set("n", "<C-h>", nvim_tmux_nav.NvimTmuxNavigateLeft) -- Navigate to the left pane
|
||||
vim.keymap.set("n", "<C-j>", nvim_tmux_nav.NvimTmuxNavigateDown) -- Navigate to the bottom pane
|
||||
vim.keymap.set("n", "<C-k>", nvim_tmux_nav.NvimTmuxNavigateUp) -- Navigate to the top pane
|
||||
vim.keymap.set("n", "<C-l>", nvim_tmux_nav.NvimTmuxNavigateRight) -- Navigate to the right pane
|
||||
vim.keymap.set("n", "<C-\\>", nvim_tmux_nav.NvimTmuxNavigateLastActive) -- Navigate to the last active pane
|
||||
vim.keymap.set("n", "<C-Space>", nvim_tmux_nav.NvimTmuxNavigateNext) -- Navigate to the next pane
|
||||
|
||||
----- OBSIDIAN -----
|
||||
vim.keymap.set("n", "<leader>oc", "<cmd>ObsidianCheck<CR>", { desc = "Obsidian Check Checkbox" })
|
||||
vim.keymap.set("n", "<leader>ot", "<cmd>ObsidianTemplate<CR>", { desc = "Insert Obsidian Template" })
|
||||
vim.keymap.set("n", "<leader>oo", "<cmd>Obsidian Open<CR>", { desc = "Open in Obsidian App" })
|
||||
vim.keymap.set("n", "<leader>ob", "<cmd>ObsidianBacklinks<CR>", { desc = "Show ObsidianBacklinks" })
|
||||
vim.keymap.set("n", "<leader>ol", "<cmd>ObsidianLinks<CR>", { desc = "Show ObsidianLinks" })
|
||||
vim.keymap.set("n", "<leader>on", "<cmd>ObsidianNew<CR>", { desc = "Create New Note" })
|
||||
vim.keymap.set("n", "<leader>os", "<cmd>ObsidianSearch<CR>", { desc = "Search Obsidian" })
|
||||
vim.keymap.set("n", "<leader>oq", "<cmd>ObsidianQuickSwitch<CR>", { desc = "Quick Switch" })
|
||||
|
||||
----- OIL -----
|
||||
vim.keymap.set("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
|
||||
|
||||
-- Delete all buffers but the current one
|
||||
vim.keymap.set(
|
||||
"n",
|
||||
"<leader>bq",
|
||||
'<Esc>:%bdelete|edit #|normal`"<Return>',
|
||||
{ desc = "Delete other buffers but the current one" }
|
||||
)
|
||||
|
||||
-- Disable key mappings in insert mode
|
||||
vim.api.nvim_set_keymap("i", "<A-j>", "<Nop>", { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap("i", "<A-k>", "<Nop>", { noremap = true, silent = true })
|
||||
|
||||
-- Disable key mappings in normal mode
|
||||
vim.api.nvim_set_keymap("n", "<A-j>", "<Nop>", { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap("n", "<A-k>", "<Nop>", { noremap = true, silent = true })
|
||||
|
||||
-- Disable key mappings in visual block mode
|
||||
vim.api.nvim_set_keymap("x", "<A-j>", "<Nop>", { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap("x", "<A-k>", "<Nop>", { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap("x", "J", "<Nop>", { noremap = true, silent = true })
|
||||
vim.api.nvim_set_keymap("x", "K", "<Nop>", { noremap = true, silent = true })
|
||||
|
||||
-- Redefine Ctrl+s to save with the custom function
|
||||
vim.api.nvim_set_keymap("n", "<C-s>", ":lua SaveFile()<CR>", { noremap = true, silent = true })
|
||||
|
||||
-- Grep keybinding for visual mode - search selected text
|
||||
vim.keymap.set("v", "<leader>sg", function()
|
||||
-- Get the selected text
|
||||
local start_pos = vim.fn.getpos("'<")
|
||||
local end_pos = vim.fn.getpos("'>")
|
||||
local lines = vim.fn.getline(start_pos[2], end_pos[2])
|
||||
|
||||
if #lines == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
-- Handle single line selection
|
||||
if #lines == 1 then
|
||||
lines[1] = string.sub(lines[1], start_pos[3], end_pos[3])
|
||||
else
|
||||
-- Handle multi-line selection
|
||||
lines[1] = string.sub(lines[1], start_pos[3])
|
||||
lines[#lines] = string.sub(lines[#lines], 1, end_pos[3])
|
||||
end
|
||||
|
||||
local selected_text = table.concat(lines, "\n")
|
||||
|
||||
-- Escape special characters for grep
|
||||
selected_text = vim.fn.escape(selected_text, "\\.*[]^$()+?{}")
|
||||
|
||||
-- Use the selected text for grep
|
||||
if pcall(require, "snacks") then
|
||||
require("snacks").picker.grep({ search = selected_text })
|
||||
elseif pcall(require, "fzf-lua") then
|
||||
require("fzf-lua").live_grep({ search = selected_text })
|
||||
else
|
||||
vim.notify("No grep picker available", vim.log.levels.ERROR)
|
||||
end
|
||||
end, { desc = "Grep Selected Text" })
|
||||
|
||||
-- Grep keybinding for visual mode with G - search selected text at root level
|
||||
vim.keymap.set("v", "<leader>sG", function()
|
||||
-- Get git root or fallback to cwd
|
||||
local git_root = vim.fn.system("git rev-parse --show-toplevel 2>/dev/null"):gsub("\n", "")
|
||||
local root = vim.v.shell_error == 0 and git_root ~= "" and git_root or vim.fn.getcwd()
|
||||
|
||||
-- Get the selected text
|
||||
local start_pos = vim.fn.getpos("'<")
|
||||
local end_pos = vim.fn.getpos("'>")
|
||||
local lines = vim.fn.getline(start_pos[2], end_pos[2])
|
||||
|
||||
if #lines == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
-- Handle single line selection
|
||||
if #lines == 1 then
|
||||
lines[1] = string.sub(lines[1], start_pos[3], end_pos[3])
|
||||
else
|
||||
-- Handle multi-line selection
|
||||
lines[1] = string.sub(lines[1], start_pos[3])
|
||||
lines[#lines] = string.sub(lines[#lines], 1, end_pos[3])
|
||||
end
|
||||
|
||||
local selected_text = table.concat(lines, "\n")
|
||||
|
||||
-- Escape special characters for grep
|
||||
selected_text = vim.fn.escape(selected_text, "\\.*[]^$()+?{}")
|
||||
|
||||
-- Use the selected text for grep at root level
|
||||
if pcall(require, "snacks") then
|
||||
require("snacks").picker.grep({ search = selected_text, cwd = root })
|
||||
elseif pcall(require, "fzf-lua") then
|
||||
require("fzf-lua").live_grep({ search = selected_text, cwd = root })
|
||||
else
|
||||
vim.notify("No grep picker available", vim.log.levels.ERROR)
|
||||
end
|
||||
end, { desc = "Grep Selected Text (Root Dir)" })
|
||||
|
||||
-- Delete all marks
|
||||
vim.keymap.set("n", "<leader>md", function()
|
||||
vim.cmd("delmarks!")
|
||||
vim.cmd("delmarks A-Z0-9")
|
||||
vim.notify("All marks deleted")
|
||||
end, { desc = "Delete all marks" })
|
||||
|
||||
-- Custom save function
|
||||
function SaveFile()
|
||||
-- Check if a buffer with a file is open
|
||||
if vim.fn.empty(vim.fn.expand("%:t")) == 1 then
|
||||
vim.notify("No file to save", vim.log.levels.WARN)
|
||||
return
|
||||
end
|
||||
|
||||
local filename = vim.fn.expand("%:t") -- Get only the filename
|
||||
local success, err = pcall(function()
|
||||
vim.cmd("silent! write") -- Try to save the file without showing the default message
|
||||
end)
|
||||
|
||||
if success then
|
||||
vim.notify(filename .. " Saved!") -- Show only the custom message if successful
|
||||
else
|
||||
vim.notify("Error: " .. err, vim.log.levels.ERROR) -- Show the error message if it fails
|
||||
end
|
||||
end
|
||||
107
mg_dotfiles/nvim/lua/config/lazy.lua
Normal file
107
mg_dotfiles/nvim/lua/config/lazy.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
-- This file contains the configuration for setting up the lazy.nvim plugin manager in Neovim.
|
||||
|
||||
-- Node.js configuration - always use latest stable version
|
||||
vim.g.node_host_prog = vim.fn.exepath("node") or "/usr/local/bin/node"
|
||||
|
||||
-- Spell-checking
|
||||
vim.opt.spell = true -- activa spell checker
|
||||
vim.opt.spelllang = { "en" }
|
||||
|
||||
-- Define the path to the lazy.nvim plugin
|
||||
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
|
||||
|
||||
-- Check if the lazy.nvim plugin is not already installed
|
||||
if not vim.loop.fs_stat(lazypath) then
|
||||
-- Bootstrap lazy.nvim by cloning the repository
|
||||
-- stylua: ignore
|
||||
vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", "--branch=stable",
|
||||
lazypath })
|
||||
end
|
||||
|
||||
-- Prepend the lazy.nvim path to the runtime path
|
||||
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)
|
||||
|
||||
-- Fix copy and paste in WSL (Windows Subsystem for Linux)
|
||||
vim.opt.clipboard = "unnamedplus" -- Use the system clipboard for all operations
|
||||
if vim.fn.has("wsl") == 1 then
|
||||
vim.g.clipboard = {
|
||||
name = "win32yank", -- Use win32yank for clipboard operations
|
||||
copy = {
|
||||
["+"] = "win32yank.exe -i --crlf", -- Command to copy to the system clipboard
|
||||
["*"] = "win32yank.exe -i --crlf", -- Command to copy to the primary clipboard
|
||||
},
|
||||
paste = {
|
||||
["+"] = "win32yank.exe -o --lf", -- Command to paste from the system clipboard
|
||||
["*"] = "win32yank.exe -o --lf", -- Command to paste from the primary clipboard
|
||||
},
|
||||
cache_enabled = false, -- Disable clipboard caching
|
||||
}
|
||||
end
|
||||
|
||||
-- Setup lazy.nvim with the specified configuration
|
||||
require("lazy").setup({
|
||||
spec = {
|
||||
-- Add LazyVim and import its plugins
|
||||
{ "LazyVim/LazyVim", import = "lazyvim.plugins" },
|
||||
-- Import any extra modules here
|
||||
-- Editor plugins
|
||||
{ import = "lazyvim.plugins.extras.editor.harpoon2" },
|
||||
{ import = "lazyvim.plugins.extras.editor.mini-files" },
|
||||
-- { import = "lazyvim.plugins.extras.editor.snacks_explorer" },
|
||||
{ import = "lazyvim.plugins.extras.editor.snacks_picker" },
|
||||
|
||||
-- Debgugging plugins
|
||||
{ import = "lazyvim.plugins.extras.dap.core" },
|
||||
|
||||
-- Formatting plugins
|
||||
{ import = "lazyvim.plugins.extras.formatting.biome" },
|
||||
{ import = "lazyvim.plugins.extras.formatting.prettier" },
|
||||
|
||||
-- Linting plugins
|
||||
{ import = "lazyvim.plugins.extras.linting.eslint" },
|
||||
|
||||
-- Language support plugins
|
||||
{ import = "lazyvim.plugins.extras.lang.json" },
|
||||
{ import = "lazyvim.plugins.extras.lang.markdown" },
|
||||
|
||||
-- Coding plugins
|
||||
{ import = "lazyvim.plugins.extras.coding.mini-surround" },
|
||||
{ import = "lazyvim.plugins.extras.editor.mini-diff" },
|
||||
{ import = "lazyvim.plugins.extras.coding.blink" },
|
||||
|
||||
-- Utility plugins
|
||||
{ import = "lazyvim.plugins.extras.util.mini-hipatterns" },
|
||||
|
||||
-- AI plugins
|
||||
{ import = "lazyvim.plugins.extras.ai.copilot" },
|
||||
|
||||
-- Import/override with your plugins
|
||||
{ import = "plugins" },
|
||||
},
|
||||
defaults = {
|
||||
-- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
|
||||
-- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
|
||||
lazy = false,
|
||||
-- It's recommended to leave version=false for now, since a lot of the plugins that support versioning
|
||||
-- have outdated releases, which may break your Neovim install.
|
||||
version = false, -- Always use the latest git commit
|
||||
-- version = "*", -- Try installing the latest stable version for plugins that support semver
|
||||
},
|
||||
install = { colorscheme = { "tokyonight", "habamax" } }, -- Specify colorschemes to install
|
||||
checker = { enabled = true }, -- Automatically check for plugin updates
|
||||
performance = {
|
||||
rtp = {
|
||||
-- Disable some runtime path plugins to improve performance
|
||||
disabled_plugins = {
|
||||
"gzip",
|
||||
-- "matchit",
|
||||
-- "matchparen",
|
||||
-- "netrwPlugin",
|
||||
"tarPlugin",
|
||||
"tohtml",
|
||||
"tutor",
|
||||
"zipPlugin",
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
241
mg_dotfiles/nvim/lua/config/nodejs.lua
Normal file
241
mg_dotfiles/nvim/lua/config/nodejs.lua
Normal file
@@ -0,0 +1,241 @@
|
||||
-- Node.js configuration for Neovim
|
||||
-- This ensures Neovim uses the SYSTEM Node.js, not project-specific versions
|
||||
-- This prevents issues when working with old projects that use Node < 18
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Function to get system Node.js path (avoiding project-specific versions)
|
||||
local function get_system_node()
|
||||
-- Priority order for system Node.js (avoiding project overrides)
|
||||
local system_paths = {
|
||||
"/opt/homebrew/bin/node", -- Homebrew on Apple Silicon
|
||||
"/usr/local/bin/node", -- Homebrew on Intel Mac or standard install
|
||||
vim.fn.expand("~/.volta/bin/node"), -- Volta's global Node
|
||||
vim.fn.expand("~/.nvm/versions/node/*/bin/node"), -- NVM default version
|
||||
vim.fn.expand("~/.nix-profile/bin/node"), -- Nix
|
||||
"/usr/bin/node", -- System default
|
||||
}
|
||||
|
||||
-- First try to find a system Node.js directly
|
||||
for _, path in ipairs(system_paths) do
|
||||
-- Handle glob patterns (for nvm)
|
||||
if path:match("%*") then
|
||||
local expanded = vim.fn.glob(path, false, true)
|
||||
if #expanded > 0 then
|
||||
-- Get the latest version from nvm
|
||||
table.sort(expanded, function(a, b)
|
||||
return a > b
|
||||
end)
|
||||
path = expanded[1]
|
||||
else
|
||||
goto continue
|
||||
end
|
||||
end
|
||||
|
||||
if vim.fn.executable(path) == 1 then
|
||||
return path
|
||||
end
|
||||
|
||||
::continue::
|
||||
end
|
||||
|
||||
-- Fallback to whatever is in PATH (but warn if it might be project-specific)
|
||||
return vim.fn.exepath("node")
|
||||
end
|
||||
|
||||
-- Function to setup Node.js for Neovim
|
||||
local function setup_nodejs()
|
||||
-- Get system Node.js, avoiding project-specific versions
|
||||
local node_path = get_system_node()
|
||||
|
||||
if node_path ~= "" then
|
||||
local version_output = vim.fn.system(node_path .. " --version 2>/dev/null")
|
||||
if vim.v.shell_error == 0 then
|
||||
-- Clean version string: remove newlines, ANSI escape codes, and 'v' prefix
|
||||
local version = version_output
|
||||
:gsub("\r", "") -- Remove carriage returns
|
||||
:gsub("\n", "") -- Remove newlines
|
||||
:gsub("\27%[[%d;]*%a", "") -- Remove ANSI escape sequences
|
||||
:gsub("^v", "") -- Remove 'v' prefix
|
||||
:match("(%d+%.%d+%.%d+)") -- Extract version number pattern
|
||||
|
||||
if version then
|
||||
local major_version = tonumber(version:match("^(%d+)"))
|
||||
|
||||
if major_version and major_version >= 18 then
|
||||
-- Set the Node.js host program
|
||||
vim.g.node_host_prog = node_path
|
||||
|
||||
-- Set npm path
|
||||
local npm_path = vim.fn.exepath("npm")
|
||||
if npm_path ~= "" then
|
||||
vim.g.npm_host_prog = npm_path
|
||||
end
|
||||
|
||||
if vim.g.debug_nodejs or vim.env.DEBUG_NODEJS then
|
||||
print("✓ Node.js for Neovim: " .. node_path .. " (v" .. version .. ")")
|
||||
|
||||
-- Detect which manager is being used
|
||||
if node_path:match("%.volta/") then
|
||||
print(" Using Volta-managed Node.js")
|
||||
elseif node_path:match("%.nvm/") then
|
||||
print(" Using NVM-managed Node.js")
|
||||
elseif node_path:match("%.nix%-profile/") then
|
||||
print(" Using Nix-managed Node.js")
|
||||
elseif node_path:match("/homebrew/") then
|
||||
print(" Using Homebrew-managed Node.js")
|
||||
else
|
||||
print(" Using system Node.js")
|
||||
end
|
||||
end
|
||||
|
||||
return true, version
|
||||
else
|
||||
-- Provide specific upgrade instructions based on the detected manager
|
||||
local upgrade_msg = "⚠️ Node.js version "
|
||||
.. version
|
||||
.. " is too old. Neovim requires v18+ (v22+ recommended).\n\n"
|
||||
|
||||
if node_path:match("/homebrew/") then
|
||||
upgrade_msg = upgrade_msg .. "To upgrade with Homebrew:\n brew upgrade node"
|
||||
elseif node_path:match("%.volta/") then
|
||||
upgrade_msg = upgrade_msg .. "To upgrade with Volta:\n volta install node@latest"
|
||||
elseif node_path:match("%.nvm/") then
|
||||
upgrade_msg = upgrade_msg .. "To upgrade with NVM:\n nvm install --lts\n nvm alias default lts/*"
|
||||
elseif node_path:match("%.nix%-profile/") then
|
||||
upgrade_msg = upgrade_msg .. "To upgrade with Nix:\n nix profile upgrade nixpkgs#nodejs"
|
||||
else
|
||||
upgrade_msg = upgrade_msg .. "Please upgrade Node.js to v18 or higher using your package manager."
|
||||
end
|
||||
|
||||
upgrade_msg = upgrade_msg .. "\n\nNote: Neovim uses the SYSTEM Node.js, not project-specific versions."
|
||||
|
||||
vim.notify(upgrade_msg, vim.log.levels.WARN)
|
||||
vim.g.node_host_prog = node_path
|
||||
return true, version
|
||||
end
|
||||
else
|
||||
-- Handle case where version parsing failed
|
||||
vim.notify(
|
||||
"⚠️ Could not parse Node.js version from: "
|
||||
.. version_output
|
||||
.. "\nPlease ensure Node.js is properly installed.",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return false, nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
vim.notify(
|
||||
"⚠️ Node.js not found! Some plugins may not work correctly.\nInstall Node.js with:\n brew install node",
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
return false, nil
|
||||
end
|
||||
|
||||
-- Function to check if we're using a recent Node.js version
|
||||
local function check_node_version()
|
||||
if not vim.g.node_host_prog then
|
||||
return
|
||||
end
|
||||
|
||||
local version_output = vim.fn.system(vim.g.node_host_prog .. " --version 2>/dev/null")
|
||||
if vim.v.shell_error ~= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local version = version_output:gsub("\n", ""):gsub("v", "")
|
||||
local major_version = tonumber(version:match("^(%d+)"))
|
||||
|
||||
if major_version then
|
||||
if major_version >= 18 and major_version < 22 then
|
||||
if vim.g.debug_nodejs then
|
||||
vim.notify(
|
||||
"ℹ️ Node.js v" .. version .. " works but v22+ is recommended for optimal performance.",
|
||||
vim.log.levels.INFO
|
||||
)
|
||||
end
|
||||
elseif major_version < 18 then
|
||||
vim.notify(
|
||||
"⚠️ Node.js version " .. version .. " is too old. Neovim requires v18+ (v22+ recommended).",
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Main setup function
|
||||
function M.setup(opts)
|
||||
opts = opts or {}
|
||||
|
||||
-- Setup Node.js
|
||||
local success, version = setup_nodejs()
|
||||
|
||||
if success and not opts.silent then
|
||||
check_node_version()
|
||||
end
|
||||
|
||||
return success
|
||||
end
|
||||
|
||||
-- Function to get current Node.js info
|
||||
function M.info()
|
||||
if not vim.g.node_host_prog then
|
||||
print("Node.js: Not configured")
|
||||
return
|
||||
end
|
||||
|
||||
local version_output = vim.fn.system(vim.g.node_host_prog .. " --version 2>/dev/null")
|
||||
if vim.v.shell_error ~= 0 then
|
||||
print("Node.js: Error getting version")
|
||||
return
|
||||
end
|
||||
|
||||
local version = version_output:gsub("\n", ""):gsub("v", "")
|
||||
print("Node.js for Neovim: " .. vim.g.node_host_prog .. " (v" .. version .. ")")
|
||||
|
||||
-- Detect source
|
||||
if vim.g.node_host_prog:match("%.volta/") then
|
||||
print("Source: Volta-managed")
|
||||
elseif vim.g.node_host_prog:match("%.nvm/") then
|
||||
print("Source: NVM-managed")
|
||||
elseif vim.g.node_host_prog:match("%.nix%-profile/") then
|
||||
print("Source: Nix-managed")
|
||||
elseif vim.g.node_host_prog:match("/homebrew/") then
|
||||
print("Source: Homebrew-managed")
|
||||
else
|
||||
print("Source: System")
|
||||
end
|
||||
|
||||
if vim.g.npm_host_prog then
|
||||
print("npm: " .. vim.g.npm_host_prog)
|
||||
end
|
||||
|
||||
if vim.g.debug_nodejs then
|
||||
print("\nPATH: " .. (vim.env.PATH or "not set"))
|
||||
end
|
||||
end
|
||||
|
||||
-- Command to manually refresh Node.js configuration
|
||||
vim.api.nvim_create_user_command("NodeRefresh", function()
|
||||
M.setup({ silent = false })
|
||||
M.info()
|
||||
end, { desc = "Refresh Node.js configuration" })
|
||||
|
||||
-- Command to show Node.js info
|
||||
vim.api.nvim_create_user_command("NodeInfo", function()
|
||||
M.info()
|
||||
end, { desc = "Show Node.js configuration info" })
|
||||
|
||||
-- Command to debug Node.js PATH issues
|
||||
vim.api.nvim_create_user_command("NodeDebug", function()
|
||||
vim.g.debug_nodejs = true
|
||||
print("=== Node.js Debug Mode Enabled ===")
|
||||
M.setup({ silent = false })
|
||||
M.info()
|
||||
print("=== End Debug Info ===")
|
||||
vim.g.debug_nodejs = false
|
||||
end, { desc = "Debug Node.js configuration and PATH" })
|
||||
|
||||
return M
|
||||
3
mg_dotfiles/nvim/lua/config/options.lua
Normal file
3
mg_dotfiles/nvim/lua/config/options.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
-- Options are automatically loaded before lazy.nvim startup
|
||||
-- Default options that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/options.lua
|
||||
-- Add any additional options here
|
||||
Reference in New Issue
Block a user