Refactor: Replace users with home
This commit is contained in:
parent
36a22dc58a
commit
aaaf4808f3
65 changed files with 17 additions and 25 deletions
59
dotfiles/nvim/lua/util/get_distro.lua
Normal file
59
dotfiles/nvim/lua/util/get_distro.lua
Normal 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
|
||||
|
7
dotfiles/nvim/lua/util/hl.lua
Normal file
7
dotfiles/nvim/lua/util/hl.lua
Normal 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
|
9
dotfiles/nvim/lua/util/map.lua
Normal file
9
dotfiles/nvim/lua/util/map.lua
Normal 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
|
||||
|
27
dotfiles/nvim/lua/util/require_dir.lua
Normal file
27
dotfiles/nvim/lua/util/require_dir.lua
Normal 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
|
||||
|
11
dotfiles/nvim/lua/util/rgb_to_hex.lua
Normal file
11
dotfiles/nvim/lua/util/rgb_to_hex.lua
Normal 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
|
Loading…
Add table
Add a link
Reference in a new issue