style: re-format
This commit is contained in:
+42
-42
@@ -3,69 +3,69 @@ local bind = {}
|
||||
bind.leader = "SUPER"
|
||||
|
||||
local function merge(...)
|
||||
local out = {}
|
||||
local out = {}
|
||||
|
||||
for _, t in ipairs({ ... }) do
|
||||
if t ~= nil then
|
||||
for k, v in pairs(t) do
|
||||
out[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
for _, t in ipairs({ ... }) do
|
||||
if t ~= nil then
|
||||
for k, v in pairs(t) do
|
||||
out[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return out
|
||||
return out
|
||||
end
|
||||
|
||||
function bind.with_leader(keys)
|
||||
if keys == nil or keys == "" then
|
||||
return bind.leader
|
||||
end
|
||||
if keys == nil or keys == "" then
|
||||
return bind.leader
|
||||
end
|
||||
|
||||
return bind.leader .. " + " .. keys
|
||||
return bind.leader .. " + " .. keys
|
||||
end
|
||||
|
||||
function bind.key(keys, dispatcher, desc, opts)
|
||||
local flags = merge(opts)
|
||||
local flags = merge(opts)
|
||||
|
||||
if desc ~= nil then
|
||||
flags.description = desc
|
||||
end
|
||||
if desc ~= nil then
|
||||
flags.description = desc
|
||||
end
|
||||
|
||||
return hl.bind(keys, dispatcher, flags)
|
||||
return hl.bind(keys, dispatcher, flags)
|
||||
end
|
||||
|
||||
function bind.set(table)
|
||||
local keys = table.keys
|
||||
local dispatcher = table.dispatcher
|
||||
local desc = ""
|
||||
local opts = {}
|
||||
if table.desc ~= nil and table.desc ~= "" then
|
||||
desc = table.desc
|
||||
end
|
||||
if table.opts ~= nil then
|
||||
opts = table.opts
|
||||
end
|
||||
bind.key(keys, dispatcher, desc, opts)
|
||||
local keys = table.keys
|
||||
local dispatcher = table.dispatcher
|
||||
local desc = ""
|
||||
local opts = {}
|
||||
if table.desc ~= nil and table.desc ~= "" then
|
||||
desc = table.desc
|
||||
end
|
||||
if table.opts ~= nil then
|
||||
opts = table.opts
|
||||
end
|
||||
bind.key(keys, dispatcher, desc, opts)
|
||||
end
|
||||
|
||||
function bind.map(table)
|
||||
for _, item in pairs(table) do
|
||||
bind.set(item)
|
||||
end
|
||||
for _, item in pairs(table) do
|
||||
bind.set(item)
|
||||
end
|
||||
end
|
||||
|
||||
function bind.layout_dispatcher(actions, fallback)
|
||||
return function()
|
||||
local ws = hl.get_active_special_workspace() or hl.get_active_workspace()
|
||||
if not ws then
|
||||
return
|
||||
end
|
||||
return function()
|
||||
local ws = hl.get_active_special_workspace() or hl.get_active_workspace()
|
||||
if not ws then
|
||||
return
|
||||
end
|
||||
|
||||
local action = actions[ws.tiled_layout] or fallback
|
||||
if action then
|
||||
hl.dispatch(action)
|
||||
end
|
||||
end
|
||||
local action = actions[ws.tiled_layout] or fallback
|
||||
if action then
|
||||
hl.dispatch(action)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return bind
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
local M = {}
|
||||
|
||||
function M.map(event, func_list)
|
||||
for _, func in pairs(func_list) do
|
||||
hl.on(event, func)
|
||||
end
|
||||
for _, func in pairs(func_list) do
|
||||
hl.on(event, func)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
+2
-2
@@ -1,12 +1,12 @@
|
||||
HOME = os.getenv("HOME")
|
||||
CONFIG_HOME = os.getenv("XDG_CONFIG_HOME")
|
||||
if not CONFIG_HOME then
|
||||
CONFIG_HOME = HOME .. "/.config"
|
||||
CONFIG_HOME = HOME .. "/.config"
|
||||
end
|
||||
HYPR = CONFIG_HOME .. "/hypr"
|
||||
USER_CONFIG = HYPR .. "/lua/user"
|
||||
|
||||
DATA_HOME = os.getenv("XDG_DATA_HOME")
|
||||
if not DATA_HOME then
|
||||
DATA_HOME = HOME .. "/.local/share"
|
||||
DATA_HOME = HOME .. "/.local/share"
|
||||
end
|
||||
|
||||
+12
-12
@@ -23,9 +23,9 @@ settings["font_family"] = "FiraCode Nerd Font"
|
||||
|
||||
---@type table<string, string>
|
||||
settings["apps"] = {
|
||||
terminal = "kitty",
|
||||
file_manager = "thunar",
|
||||
browser = "chromium",
|
||||
terminal = "kitty",
|
||||
file_manager = "thunar",
|
||||
browser = "chromium",
|
||||
}
|
||||
|
||||
---@type "catppuccin"|"catppuccin-mocha"
|
||||
@@ -36,19 +36,19 @@ settings["systemd"] = false
|
||||
|
||||
---@type table<string, boolean>
|
||||
settings["modules"] = {
|
||||
hypridle = true,
|
||||
waybar = true,
|
||||
swaync = true,
|
||||
swayosd = true,
|
||||
cliphist = true,
|
||||
pypr = true,
|
||||
fcitx5 = false,
|
||||
rofi = true,
|
||||
hypridle = true,
|
||||
waybar = true,
|
||||
swaync = true,
|
||||
swayosd = true,
|
||||
cliphist = true,
|
||||
pypr = true,
|
||||
fcitx5 = false,
|
||||
rofi = true,
|
||||
}
|
||||
|
||||
---@type table<string, boolean>
|
||||
settings["plugins"] = {
|
||||
hyprexpo = false,
|
||||
hyprexpo = false,
|
||||
}
|
||||
|
||||
return require("lua.lib.utils").extend_config(settings, "lua.user.settings")
|
||||
|
||||
+13
-13
@@ -2,30 +2,30 @@ local utils = require("lua.lib.utils")
|
||||
local M = {}
|
||||
|
||||
function M.is_user_unit_exists(unit)
|
||||
return utils.command_success("systemctl --user cat " .. utils.shell_quote(unit) .. " >/dev/null 2>&1")
|
||||
return utils.command_success("systemctl --user cat " .. utils.shell_quote(unit) .. " >/dev/null 2>&1")
|
||||
end
|
||||
|
||||
M.user_unit_dir = CONFIG_HOME .. "/systemd/user"
|
||||
|
||||
function M.ensure_user_unit(unit, source)
|
||||
if M.is_user_unit_exists(unit) then
|
||||
return true
|
||||
end
|
||||
if M.is_user_unit_exists(unit) then
|
||||
return true
|
||||
end
|
||||
|
||||
local target_dir = M.user_unit_dir
|
||||
local target = target_dir .. "/" .. unit
|
||||
local target_dir = M.user_unit_dir
|
||||
local target = target_dir .. "/" .. unit
|
||||
|
||||
local cmd = table.concat({
|
||||
"mkdir -p " .. utils.shell_quote(target_dir),
|
||||
"ln -s " .. utils.shell_quote(source) .. " " .. utils.shell_quote(target),
|
||||
"systemctl --user daemon-reload",
|
||||
}, " && ")
|
||||
local cmd = table.concat({
|
||||
"mkdir -p " .. utils.shell_quote(target_dir),
|
||||
"ln -s " .. utils.shell_quote(source) .. " " .. utils.shell_quote(target),
|
||||
"systemctl --user daemon-reload",
|
||||
}, " && ")
|
||||
|
||||
return utils.command_success(cmd)
|
||||
return utils.command_success(cmd)
|
||||
end
|
||||
|
||||
function M.start_user_unit(unit)
|
||||
return utils.command_success("systemctl --user start " .. utils.shell_quote(unit) .. " >/dev/null 2>&1")
|
||||
return utils.command_success("systemctl --user start " .. utils.shell_quote(unit) .. " >/dev/null 2>&1")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
+82
-82
@@ -3,134 +3,134 @@ require("lua.lib.globals")
|
||||
local M = {}
|
||||
|
||||
local function is_table(x)
|
||||
return type(x) == "table"
|
||||
return type(x) == "table"
|
||||
end
|
||||
|
||||
local function is_list(t)
|
||||
if type(t) ~= "table" then
|
||||
return false
|
||||
end
|
||||
if type(t) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
local n = 0
|
||||
local n = 0
|
||||
|
||||
for k, _ in pairs(t) do
|
||||
if type(k) ~= "number" then
|
||||
return false
|
||||
end
|
||||
for k, _ in pairs(t) do
|
||||
if type(k) ~= "number" then
|
||||
return false
|
||||
end
|
||||
|
||||
if k > n then
|
||||
n = k
|
||||
end
|
||||
end
|
||||
if k > n then
|
||||
n = k
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, n do
|
||||
if t[i] == nil then
|
||||
return false
|
||||
end
|
||||
end
|
||||
for i = 1, n do
|
||||
if t[i] == nil then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
return true
|
||||
end
|
||||
|
||||
function M.list_extend(dst, src)
|
||||
for _, value in ipairs(src) do
|
||||
table.insert(dst, value)
|
||||
end
|
||||
for _, value in ipairs(src) do
|
||||
table.insert(dst, value)
|
||||
end
|
||||
|
||||
return dst
|
||||
return dst
|
||||
end
|
||||
|
||||
local function deepcopy(value, seen)
|
||||
if type(value) ~= "table" then
|
||||
return value
|
||||
end
|
||||
if type(value) ~= "table" then
|
||||
return value
|
||||
end
|
||||
|
||||
seen = seen or {}
|
||||
if seen[value] then
|
||||
return seen[value]
|
||||
end
|
||||
seen = seen or {}
|
||||
if seen[value] then
|
||||
return seen[value]
|
||||
end
|
||||
|
||||
local result = {}
|
||||
seen[value] = result
|
||||
local result = {}
|
||||
seen[value] = result
|
||||
|
||||
for k, v in pairs(value) do
|
||||
result[deepcopy(k, seen)] = deepcopy(v, seen)
|
||||
end
|
||||
for k, v in pairs(value) do
|
||||
result[deepcopy(k, seen)] = deepcopy(v, seen)
|
||||
end
|
||||
|
||||
return result
|
||||
return result
|
||||
end
|
||||
|
||||
function M.tbl_recursive_merge(defaults, overrides)
|
||||
local result = deepcopy(defaults)
|
||||
local result = deepcopy(defaults)
|
||||
|
||||
if not is_table(overrides) then
|
||||
return result
|
||||
end
|
||||
if not is_table(overrides) then
|
||||
return result
|
||||
end
|
||||
|
||||
for key, value in pairs(overrides) do
|
||||
if is_table(value) and is_table(result[key]) then
|
||||
result[key] = M.tbl_recursive_merge(result[key], value)
|
||||
else
|
||||
result[key] = deepcopy(value)
|
||||
end
|
||||
end
|
||||
for key, value in pairs(overrides) do
|
||||
if is_table(value) and is_table(result[key]) then
|
||||
result[key] = M.tbl_recursive_merge(result[key], value)
|
||||
else
|
||||
result[key] = deepcopy(value)
|
||||
end
|
||||
end
|
||||
|
||||
return result
|
||||
return result
|
||||
end
|
||||
|
||||
function M.extend_config(defaults, user_module)
|
||||
local file = HYPR .. "/" .. string.gsub(user_module, "%.", "/") .. ".lua"
|
||||
if not M.is_file_exists(file) then
|
||||
print(file .. " not found.")
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
local ok, overrides = pcall(require, user_module)
|
||||
local file = HYPR .. "/" .. string.gsub(user_module, "%.", "/") .. ".lua"
|
||||
if not M.is_file_exists(file) then
|
||||
print(file .. " not found.")
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
local ok, overrides = pcall(require, user_module)
|
||||
|
||||
if not ok then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
if not ok then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
|
||||
if type(overrides) ~= "table" then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
if type(overrides) ~= "table" then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
|
||||
return M.tbl_recursive_merge(defaults, overrides)
|
||||
return M.tbl_recursive_merge(defaults, overrides)
|
||||
end
|
||||
|
||||
function M.is_file_exists(name)
|
||||
local f = io.open(name, "r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
local f = io.open(name, "r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function M.exec_if_file_extes(file)
|
||||
if M.is_file_exists(file) then
|
||||
hl.exec_cmd(file)
|
||||
else
|
||||
hl.notification.create({ file .. " doesn't extist", 5000, 0 })
|
||||
end
|
||||
if M.is_file_exists(file) then
|
||||
hl.exec_cmd(file)
|
||||
else
|
||||
hl.notification.create({ file .. " doesn't extist", 5000, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
function M.create_if_not_exists(path)
|
||||
if not M.is_file_exists(path) then
|
||||
os.execute('mkdir -pv "$(dirname "' .. path .. '")"')
|
||||
os.execute("touch " .. path)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
if not M.is_file_exists(path) then
|
||||
os.execute('mkdir -pv "$(dirname "' .. path .. '")"')
|
||||
os.execute("touch " .. path)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function M.shell_quote(s)
|
||||
return "'" .. tostring(s):gsub("'", "'\\''") .. "'"
|
||||
return "'" .. tostring(s):gsub("'", "'\\''") .. "'"
|
||||
end
|
||||
|
||||
function M.command_success(cmd)
|
||||
local ok = os.execute(cmd)
|
||||
return ok == true or ok == 0
|
||||
local ok = os.execute(cmd)
|
||||
return ok == true or ok == 0
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user