From 629620be0e6491891a5194537f046f862354c2ea Mon Sep 17 00:00:00 2001 From: Ahmed Zamouche Date: Mon, 4 Dec 2023 22:06:02 +0100 Subject: [PATCH] Add more utils function --- lua/user/utils.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lua/user/utils.lua b/lua/user/utils.lua index bd23bc3..2ffd07a 100644 --- a/lua/user/utils.lua +++ b/lua/user/utils.lua @@ -52,4 +52,34 @@ function M.get_values(t, key) return values end +function M.contains(table, val) + for i = 1, #table do + if table[i] == val then + return true + end + end + return false +end + +M.os = {} + +function M.os.name() + -- Unix, Linux variants + local fh, err = assert(io.popen("uname -o 2>/dev/null", "r")) + if fh then + return fh:read() + end + return "Windows" +end + +function M.os.home() + if M.os.name() == "Windows" then + return os.getenv("UserProfile") + elseif M.contains({ "Linux", "GNU/Linux", "Darwin" }, M.os.name()) then + return os.getenv("HOME") + else + return "", false + end +end + return M