From 3cb906c14bd695b9c110ec80e472aad99f1f5d25 Mon Sep 17 00:00:00 2001 From: rootiest Date: Tue, 5 Nov 2024 05:56:49 -0500 Subject: [PATCH] feat: add function to convert Windows paths to Unix format --- lua/data/func.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/data/func.lua b/lua/data/func.lua index 05762d0..45b10cf 100644 --- a/lua/data/func.lua +++ b/lua/data/func.lua @@ -1759,5 +1759,23 @@ function M.pick(cmd, provider, options) return false end +--- Converts a Windows path to a Unix path +--- If the path is already in Unix format, it will return the original path. +--- You can pass any path whose format is uncertain to this function to ensure +--- the correct format is used. +---@param path string The path to convert +---@return string The converted path +function M.convert_path(path) + -- Check if the path is a Windows path (e.g., C:\ or D:\) + if path:match("^[A-Za-z]:\\") or path:match("^[A-Za-z]:/") then + -- Convert forward slashes (/) to backslashes (\) + local converted_path = path:gsub("/", "\\") + return converted_path + else + -- Return the original path if it's not a Windows path + return path + end +end + -- Export the module return M