diff options
Diffstat (limited to 'configs/nvim/lua/crupest/system/find.lua')
-rw-r--r-- | configs/nvim/lua/crupest/system/find.lua | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/configs/nvim/lua/crupest/system/find.lua b/configs/nvim/lua/crupest/system/find.lua index 16237ec..a2631a6 100644 --- a/configs/nvim/lua/crupest/system/find.lua +++ b/configs/nvim/lua/crupest/system/find.lua @@ -5,12 +5,12 @@ local function get_exe(path) if system.is_win then local exts = { "exe", "CMD", "cmd", "ps1" } for _, ext in ipairs(exts) do - if string.find(path, "%."..ext.."$") and fs.isfile(path) then + if string.find(path, "%." .. ext .. "$") and fs.isfile(path) then return path end end for _, ext in ipairs(exts) do - local p = path.."."..ext + local p = path .. "." .. ext if fs.isfile(p) then return p end end return nil @@ -23,9 +23,18 @@ local function get_exe(path) return nil end +local function first_exe(paths) + for _, v in ipairs(paths) do + local exe = get_exe(v) + if exe then return exe end + end + + return nil +end + local function find_node_modules(path) - return fs.walk_up(path, function (current_path) - local node_modules_path = current_path.."/node_modules" + return fs.walk_up(path, function(current_path) + local node_modules_path = current_path .. "/node_modules" if fs.isdir(node_modules_path) then return node_modules_path end @@ -36,7 +45,7 @@ end local function find_npm_exe(path, exe) local node_modules_path = find_node_modules(path) if not node_modules_path then return nil end - local try_exe_path = node_modules_path.."/.bin/"..exe + local try_exe_path = node_modules_path .. "/.bin/" .. exe local exe_path = get_exe(try_exe_path) if exe_path then return exe_path end return nil @@ -44,7 +53,7 @@ end return { get_exe = get_exe, + first_exe = first_exe, find_node_modules = find_node_modules, find_npm_exe = find_npm_exe, } - |