Refactor: Replace users with home

This commit is contained in:
caem 2024-07-25 22:12:51 +02:00
parent 36a22dc58a
commit aaaf4808f3
Signed by: caem
GPG key ID: 69A830D03203405F
65 changed files with 17 additions and 25 deletions

View file

@ -0,0 +1,59 @@
local function distro_traits(name)
local icons = {
[ "unknown" ] = {
icon = "",
color = "#f3be25",
},
[ "debian" ] = {
icon = "",
color = "#d70a53",
},
[ "gentoo" ] = {
icon = "",
color = "#54487A",
},
[ "nixos" ] = {
icon = "",
color = "#5277C3",
},
[ "\"opensuse-tumbleweed\"" ] = {
icon = "",
color = "#73ba25",
},
}
local icon = icons[name]
if icon == nil then
icon = icons["unknown"]
end
return icon
end
return function()
local release_file = io.open("/etc/os-release", "rb")
if release_file == nil then
return {
name = "unknown",
traits = distro_traits("unknown"),
}
end
local content = vim.split(release_file:read("*a"), "\n")
local distro_id = nil
for _, line in ipairs(content) do
if string.sub(line, 0, 3) == "ID=" then
distro_id = string.sub(line, 4, -1)
goto distro_id_found
end
end
::distro_id_found::
release_file:close()
return {
name = distro_id,
traits = distro_traits(distro_id)
}
end

View file

@ -0,0 +1,7 @@
return function (name)
local hl = vim.api.nvim_get_hl(0, { name = name })
while hl.link ~= nil do
hl = vim.api.nvim_get_hl(0, { name = hl.link })
end
return hl
end

View file

@ -0,0 +1,9 @@
return function(mode, key, mapping, comment)
local opts = {
noremap = true,
silent = true,
desc = comment
}
vim.keymap.set(mode, key, mapping, opts)
end

View file

@ -0,0 +1,27 @@
return function(dir, skip_init)
local returns = {}
local lua_files = vim.split(vim.fn.glob(dir.."/*.lua"), "\n")
local namespace = string.gsub(dir, vim.fn.stdpath("config").."/lua/", "")
namespace = string.gsub(namespace, "%/", ".")
for _, file in ipairs(lua_files) do
file = string.gsub(file, "%.lua", "")
file = string.gsub(file, dir.."/", namespace)
if skip_init and file == namespace.."init" then
goto continue
end
local require_ok, require_return = pcall(require, file)
if require_ok then
table.insert(returns, require_return)
else
vim.notify("Could not require file: '"..file.."': "..require_return, vim.log.levels.WARNING)
end
::continue::
end
return returns
end

View file

@ -0,0 +1,11 @@
return function(rgb)
if rgb == nil then
return nil
end
local r = string.format("%02x", (rgb / 65536) % 256)
local g = string.format("%02x", (rgb / 256) % 256)
local b = string.format("%02x", rgb % 256)
return "#"..r..g..b
end