From e853de1ef6e8e87085138e058a7e2efed0b29bbb Mon Sep 17 00:00:00 2001 From: cultab Date: Sat, 20 Jan 2024 00:07:49 +0200 Subject: [PATCH 1/3] fix(utils): redirect stderr so it doesn't leak --- lua/Navigator/utils.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/Navigator/utils.lua b/lua/Navigator/utils.lua index 84fddeb..c7d5e29 100644 --- a/lua/Navigator/utils.lua +++ b/lua/Navigator/utils.lua @@ -4,7 +4,7 @@ local U = {} ---@param cmd string ---@return unknown function U.execute(cmd) - local handle = assert(io.popen(cmd), string.format('[Navigator] Unable to execute cmd - %q', cmd)) + local handle = assert(io.popen(cmd .. " 2>&1"), string.format('[Navigator] Unable to execute cmd - %q', cmd)) local result = handle:read() handle:close() return result From 20bd5760c654e904cea888aaf6c069eebdbe7f9f Mon Sep 17 00:00:00 2001 From: cultab Date: Wed, 4 Sep 2024 23:25:35 +0300 Subject: [PATCH 2/3] fix: improve windows detection See original fix: https://github.com/cultab/command.nvim/commit/a8a70c262be949d0506adbe6af5255568482f0ba --- lua/Navigator/utils.lua | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lua/Navigator/utils.lua b/lua/Navigator/utils.lua index c7d5e29..fb9b6ff 100644 --- a/lua/Navigator/utils.lua +++ b/lua/Navigator/utils.lua @@ -4,20 +4,27 @@ local U = {} ---@param cmd string ---@return unknown function U.execute(cmd) - local handle = assert(io.popen(cmd .. " 2>&1"), string.format('[Navigator] Unable to execute cmd - %q', cmd)) + local handle = assert(io.popen(cmd .. ' 2>&1'), string.format('[Navigator] Unable to execute cmd - %q', cmd)) local result = handle:read() handle:close() return result end ----Returns executable suffix based on platform ----@return string -function U.suffix() - local uname = vim.loop.os_uname() - if string.find(uname.release, 'WSL.*$') or string.find(uname.sysname, '^Win') then - return '.exe' +local suffix_cache = nil +--Returns executable suffix based on platform +--- REF: Navigator.nvim +--@return string +U.suffix = function() + if not suffix_cache then + suffix_cache = '' -- default to empty, overwrite if it's windows + local uname = vim.loop.os_uname() + if string.find(uname.release, 'WSL.*$') or string.find(uname.sysname, '^Win') then -- may be windows + if os.execute('wezterm.exe') == 0 then -- if exe exists, execute if expensive so heuristics first + suffix_cache = '.exe' + end + end + return suffix_cache end - return '' end return U From 2d883e073b88c60f42b6dda3fa9253445b538aec Mon Sep 17 00:00:00 2001 From: cultab Date: Fri, 11 Oct 2024 03:28:39 +0300 Subject: [PATCH 3/3] fix: correctly hide stderr also pull suffix() from command.nvim --- lua/Navigator/utils.lua | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/lua/Navigator/utils.lua b/lua/Navigator/utils.lua index fb9b6ff..ffa0a16 100644 --- a/lua/Navigator/utils.lua +++ b/lua/Navigator/utils.lua @@ -4,27 +4,24 @@ local U = {} ---@param cmd string ---@return unknown function U.execute(cmd) - local handle = assert(io.popen(cmd .. ' 2>&1'), string.format('[Navigator] Unable to execute cmd - %q', cmd)) + local handle = assert(io.popen(cmd .. '>/dev/null 2>&1'), string.format('[Navigator] Unable to execute cmd - %q', cmd)) local result = handle:read() handle:close() return result end local suffix_cache = nil ---Returns executable suffix based on platform ---- REF: Navigator.nvim ---@return string +---Returns executable suffix based on platform +---@return string U.suffix = function() - if not suffix_cache then - suffix_cache = '' -- default to empty, overwrite if it's windows - local uname = vim.loop.os_uname() - if string.find(uname.release, 'WSL.*$') or string.find(uname.sysname, '^Win') then -- may be windows - if os.execute('wezterm.exe') == 0 then -- if exe exists, execute if expensive so heuristics first - suffix_cache = '.exe' - end - end - return suffix_cache - end + if not suffix_cache then + suffix_cache = '' -- default to empty, overwrite if it's windows + local obj = vim.system({ 'wezterm.exe', '--help' }):wait() -- if exe exists + if obj.code == 0 then + suffix_cache = '.exe' + end + end + return suffix_cache end return U