Last active
March 5, 2025 08:34
-
-
Save pierodev0/72337d08d76633aff83531a818a50128 to your computer and use it in GitHub Desktop.
fix error nvchad: error in function 'termopen' in windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Remplazar la funcion create del archivo init.lua | |
-- C:\Users\nameUser\AppData\Local\nvim-data\lazy\ui\lua\nvchad\term | |
local function create(opts) | |
local buf_exists = opts.buf | |
opts.buf = opts.buf or vim.api.nvim_create_buf(false, true) | |
-- Detectar el sistema operativo | |
local is_windows = vim.fn.has('win32') == 1 or vim.fn.has('win64') == 1 | |
-- Configurar shell según el sistema operativo | |
local shell = vim.o.shell | |
local cmd | |
-- En Windows, asegurarse de que la shell sea ejecutable y manejar espacios en rutas | |
if is_windows then | |
-- Comprobar si es PowerShell, CMD o Git Bash | |
if shell:lower():find("powershell") then | |
shell = "powershell.exe" | |
elseif shell:lower():find("cmd") then | |
shell = "cmd.exe" | |
elseif shell:lower():find("bash") or shell:lower():find("git") then | |
-- Intentar encontrar bash.exe en ubicaciones comunes | |
local possible_paths = { | |
"C:\\Program Files\\Git\\bin\\bash.exe", | |
"C:\\Program Files (x86)\\Git\\bin\\bash.exe", | |
vim.fn.expand("~/AppData/Local/Programs/Git/bin/bash.exe") | |
} | |
for _, path in ipairs(possible_paths) do | |
if vim.fn.executable(vim.fn.substitute(path, " ", "\\ ", "g")) == 1 then | |
shell = path | |
break | |
end | |
end | |
end | |
end | |
-- Verificar que la shell sea ejecutable | |
if vim.fn.executable(vim.fn.substitute(shell, " ", "\\ ", "g")) ~= 1 then | |
vim.notify("Shell no ejecutable: " .. shell .. ". Cambiando a shell por defecto.", vim.log.levels.WARN) | |
if is_windows then | |
shell = "cmd.exe" | |
else | |
shell = "/bin/bash" | |
end | |
end | |
-- Configurar el comando según los parámetros | |
if opts.cmd and opts.buf then | |
if is_windows then | |
if shell:lower():find("powershell") then | |
cmd = { shell, "-Command", format_cmd(opts.cmd) } | |
elseif shell:lower():find("cmd") then | |
cmd = { shell, "/c", format_cmd(opts.cmd) } | |
else -- Git Bash u otra shell compatible con Unix | |
cmd = { shell, "-c", format_cmd(opts.cmd) .. "; " .. shell } | |
end | |
else | |
cmd = { shell, "-c", format_cmd(opts.cmd) .. "; " .. shell } | |
end | |
else | |
cmd = { shell } | |
end | |
M.display(opts) | |
save_term_info(opts.buf, opts) | |
if not buf_exists then | |
local success, result = pcall(vim.fn.termopen, cmd, opts.termopen_opts or { detach = false }) | |
if not success then | |
vim.notify("Error al abrir terminal: " .. tostring(result) .. "\nComando: " .. vim.inspect(cmd), vim.log.levels.ERROR) | |
return false | |
end | |
end | |
vim.g.nvhterm = opts.pos == "sp" | |
vim.g.nvvterm = opts.pos == "vsp" | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment