From c0a4f96d5631ea80d3275276343875e9202d4571 Mon Sep 17 00:00:00 2001 From: Ahmed Zamouche Date: Tue, 5 Dec 2023 13:52:18 +0100 Subject: [PATCH] add path join --- lua/user/toggleterm.lua | 2 +- lua/user/utils.lua | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lua/user/toggleterm.lua b/lua/user/toggleterm.lua index eca3b92..9f41733 100644 --- a/lua/user/toggleterm.lua +++ b/lua/user/toggleterm.lua @@ -54,7 +54,7 @@ end local function get_ssh_hosts(path) local hosts = {} - path = path or utils.os.home() .. "/.ssh/config" + path = path or utils.os.path.join({ utils.os.home(), ".ssh", "config" }) if type(path) ~= "string" then print("expected arg path of type 'string' actual '" .. type(path)) diff --git a/lua/user/utils.lua b/lua/user/utils.lua index 2ffd07a..cfe6c3f 100644 --- a/lua/user/utils.lua +++ b/lua/user/utils.lua @@ -66,7 +66,7 @@ M.os = {} function M.os.name() -- Unix, Linux variants local fh, err = assert(io.popen("uname -o 2>/dev/null", "r")) - if fh then + if err ~= nil and fh then return fh:read() end return "Windows" @@ -82,4 +82,16 @@ function M.os.home() end end +M.os.path = {} + +function M.os.path.join(t) + local sep = nil + if M.os.name() == "Windows" then + sep = "\\" + else + sep = "/" + end + return table.concat(t, sep) +end + return M