init
This commit is contained in:
@@ -0,0 +1 @@
|
||||
local settings = require("lua.lib.settings")
|
||||
@@ -0,0 +1,37 @@
|
||||
local settings = require("lua.lib.settings")
|
||||
local colorscheme
|
||||
|
||||
-- currently, only catppuccin is considerd
|
||||
if settings["colorscheme"] == "catppuccin" or settings["colorscheme"] == "catppuccin-mocha" or true then
|
||||
colorscheme.rosewater = "#f5e0dc"
|
||||
colorscheme.flamingo = "#f2cdcd"
|
||||
colorscheme.pink = "#f5c2e7"
|
||||
colorscheme.mauve = "#cba6f7"
|
||||
colorscheme.red = "#f38ba8"
|
||||
colorscheme.maroon = "#eba0ac"
|
||||
colorscheme.peach = "#fab387"
|
||||
colorscheme.yellow = "#f9e2af"
|
||||
colorscheme.green = "#a6e3a1"
|
||||
colorscheme.teal = "#94e2d5"
|
||||
colorscheme.sky = "#89dceb"
|
||||
colorscheme.sapphire = "#74c7ec"
|
||||
colorscheme.blue = "#89b4fa"
|
||||
colorscheme.lavender = "#b4befe"
|
||||
colorscheme.text = "#cdd6f4"
|
||||
colorscheme.subtext1 = "#bac2de"
|
||||
colorscheme.subtext0 = "#a6adc8"
|
||||
colorscheme.overlay2 = "#9399b2"
|
||||
colorscheme.overlay1 = "#7f849c"
|
||||
colorscheme.overlay0 = "#6c7086"
|
||||
colorscheme.surface2 = "#585b70"
|
||||
colorscheme.surface1 = "#45475a"
|
||||
colorscheme.surface0 = "#313244"
|
||||
colorscheme.base = "#1e1e2e"
|
||||
colorscheme.mantle = "#181825"
|
||||
colorscheme.crust = "#11111b"
|
||||
colorscheme.foreground = colorscheme.text
|
||||
colorscheme.background = colorscheme.surface0
|
||||
colorscheme.accent = colorscheme.blue
|
||||
end
|
||||
|
||||
return colorscheme
|
||||
@@ -0,0 +1,8 @@
|
||||
local settings = require("lua.lib.settings")
|
||||
require("lua.lib.globals")
|
||||
|
||||
require("lua.conf.monitor")
|
||||
|
||||
require("lua.modules").load()
|
||||
|
||||
hl.bind("SUPER + Return", hl.dsp.exec_cmd("kitty"))
|
||||
@@ -0,0 +1,9 @@
|
||||
local settings = require("lua.lib.settings")
|
||||
|
||||
if settings["host"] == "laptop" then
|
||||
hl.monitor({
|
||||
output = "eDP-1",
|
||||
mode = "highres",
|
||||
scale = "auto",
|
||||
})
|
||||
end
|
||||
@@ -0,0 +1,41 @@
|
||||
local bind = {}
|
||||
|
||||
bind.leader = "SUPER"
|
||||
|
||||
local function merge(...)
|
||||
local out = {}
|
||||
|
||||
for _, t in ipairs({ ... }) do
|
||||
if t ~= nil then
|
||||
for k, v in pairs(t) do
|
||||
out[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return out
|
||||
end
|
||||
|
||||
local function with_leader(keys)
|
||||
if keys == nil or keys == "" then
|
||||
return bind.leader
|
||||
end
|
||||
|
||||
return bind.leader .. " + " .. keys
|
||||
end
|
||||
|
||||
function bind.key(keys, dispatcher, desc, opts)
|
||||
local flags = merge(opts)
|
||||
|
||||
if desc ~= nil then
|
||||
flags.description = desc
|
||||
end
|
||||
|
||||
return hl.bind(keys, dispatcher, flags)
|
||||
end
|
||||
|
||||
function bind.leader_key(keys, dispatcher, desc, opts)
|
||||
return bind.key(with_leader(keys), dispatcher, desc, opts)
|
||||
end
|
||||
|
||||
return bind
|
||||
@@ -0,0 +1,9 @@
|
||||
local M = {}
|
||||
|
||||
function M.map(event, func_list)
|
||||
for _, func in pairs(func_list) do
|
||||
hl.on(event, func)
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,7 @@
|
||||
HOME = os.getenv("HOME")
|
||||
CONFIG_HOME = os.getenv("XDG_CONFIG_HOME")
|
||||
if not CONFIG_HOME then
|
||||
CONFIG_HOME = HOME .. "/.config"
|
||||
end
|
||||
HYPR = CONFIG_HOME .. "/hypr"
|
||||
USER_CONFIG = HYPR .. "/lua/user"
|
||||
@@ -0,0 +1,22 @@
|
||||
local settings = {}
|
||||
|
||||
---@type string
|
||||
settings["hostname"] = ""
|
||||
|
||||
---@type "desktop"|"laptop"
|
||||
settings["profile"] = "desktop"
|
||||
|
||||
---@type "catppuccin"|"catppuccin-mocha"
|
||||
settings["colorscheme"] = "catppuccin"
|
||||
|
||||
---@type boolean
|
||||
settings["systemd"] = false
|
||||
|
||||
---@type table<string, boolean>
|
||||
settings["modules"] = {
|
||||
waybar = true,
|
||||
swaync = true,
|
||||
swayosd = true,
|
||||
}
|
||||
|
||||
return require("lua.lib.utils").extend_config(settings, "lua.user.settings")
|
||||
@@ -0,0 +1,31 @@
|
||||
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")
|
||||
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
|
||||
|
||||
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",
|
||||
}, " && ")
|
||||
|
||||
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")
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,134 @@
|
||||
-- lua/lib/utils.lua
|
||||
require("lua.lib.globals")
|
||||
local M = {}
|
||||
|
||||
local function is_table(x)
|
||||
return type(x) == "table"
|
||||
end
|
||||
|
||||
local function is_list(t)
|
||||
if type(t) ~= "table" then
|
||||
return false
|
||||
end
|
||||
|
||||
local n = 0
|
||||
|
||||
for k, _ in pairs(t) do
|
||||
if type(k) ~= "number" then
|
||||
return false
|
||||
end
|
||||
|
||||
if k > n then
|
||||
n = k
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, n do
|
||||
if t[i] == nil then
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function M.list_extend(dst, src)
|
||||
for _, value in ipairs(src) do
|
||||
table.insert(dst, value)
|
||||
end
|
||||
|
||||
return dst
|
||||
end
|
||||
|
||||
local function deepcopy(value, seen)
|
||||
if type(value) ~= "table" then
|
||||
return value
|
||||
end
|
||||
|
||||
seen = seen or {}
|
||||
if seen[value] then
|
||||
return seen[value]
|
||||
end
|
||||
|
||||
local result = {}
|
||||
seen[value] = result
|
||||
|
||||
for k, v in pairs(value) do
|
||||
result[deepcopy(k, seen)] = deepcopy(v, seen)
|
||||
end
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function M.tbl_recursive_merge(defaults, overrides)
|
||||
local result = deepcopy(defaults)
|
||||
|
||||
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
|
||||
|
||||
return result
|
||||
end
|
||||
|
||||
function M.extend_config(defaults, user_module)
|
||||
if not M.is_file_exists(HYPR .. user_module) then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
local ok, overrides = pcall(require, user_module)
|
||||
|
||||
if not ok then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
|
||||
if type(overrides) ~= "table" then
|
||||
return deepcopy(defaults)
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
end
|
||||
|
||||
function M.shell_quote(s)
|
||||
return "'" .. tostring(s):gsub("'", "'\\''") .. "'"
|
||||
end
|
||||
|
||||
function M.command_success(cmd)
|
||||
local ok = os.execute(cmd)
|
||||
return ok == true or ok == 0
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,61 @@
|
||||
local settings = require("lua.lib.settings")
|
||||
require("lua.lib.globals")
|
||||
local utils = require("lua.lib.utils")
|
||||
local events = require("lua.lib.events")
|
||||
|
||||
local M = {}
|
||||
local modules = {}
|
||||
|
||||
local function is_module_exists(name)
|
||||
return utils.is_file_exists(HYPR .. "/lua/modules/" .. name .. ".lua")
|
||||
end
|
||||
|
||||
local function load_module(name)
|
||||
if not is_module_exists(name) then
|
||||
return {}
|
||||
end
|
||||
local default_mod = require("lua.modules." .. name)
|
||||
|
||||
local user_modname = "lua.user.modules." .. name
|
||||
local mod = utils.extend_config(default_mod, user_modname)
|
||||
|
||||
return mod
|
||||
end
|
||||
|
||||
for name, enabled in pairs(settings.modules) do
|
||||
if enabled then
|
||||
local mod = load_module(name)
|
||||
table.insert(modules, {
|
||||
name = name,
|
||||
config = mod,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
M.autostart = {}
|
||||
M.autostop = {}
|
||||
M.binds = {}
|
||||
|
||||
local function collect_modules_prop(module, prop)
|
||||
if module[prop] then
|
||||
M[prop] = utils.list_extend(M[prop], module[prop])
|
||||
end
|
||||
end
|
||||
|
||||
for _, item in ipairs(modules) do
|
||||
local module = item.config
|
||||
collect_modules_prop(module, "autostart")
|
||||
collect_modules_prop(module, "autostop")
|
||||
collect_modules_prop(module, "binds")
|
||||
end
|
||||
|
||||
function M.load()
|
||||
events.map("hyprland.start", M.autostart)
|
||||
events.map("hyprland.shutdown", M.autostop)
|
||||
|
||||
for _, bind in pairs(M.binds) do
|
||||
bind()
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,36 @@
|
||||
local settings = require("lua.lib.settings")
|
||||
local systemd = require("lua.lib.systemd")
|
||||
local utils = require("lua.lib.utils")
|
||||
require("lua.lib.globals")
|
||||
local M = {}
|
||||
|
||||
local function start_swaync()
|
||||
if settings["systemd"] then
|
||||
local unit = "swaync.service"
|
||||
local source = CONFIG_HOME .. "hypr/systemd/" .. unit
|
||||
|
||||
if systemd.ensure_user_unit(unit, source) then
|
||||
hl.exec_cmd("systemctl --user start swaync")
|
||||
else
|
||||
hl.exec_cmd("swaync")
|
||||
end
|
||||
else
|
||||
hl.exec_cmd("swaync")
|
||||
end
|
||||
end
|
||||
|
||||
local function stop_swaync()
|
||||
if settings["systemd"] and utils.command_success("systemctl --user status swaync") then
|
||||
hl.exec_cmd("systemctl --user stop swaync")
|
||||
end
|
||||
end
|
||||
|
||||
M.autostart = {
|
||||
start_swaync,
|
||||
}
|
||||
|
||||
M.autostop = {
|
||||
stop_swaync,
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,19 @@
|
||||
local M = {}
|
||||
local bind = require("lua.lib.bind")
|
||||
|
||||
local function start_waybar()
|
||||
hl.exec_cmd("~/dotfiles/waybar/launch.sh")
|
||||
end
|
||||
|
||||
M.autostart = {
|
||||
start_waybar,
|
||||
}
|
||||
|
||||
M.binds = {
|
||||
function()
|
||||
bind.leader_key("SHIFT + B", hl.dsp.exec_cmd("~/dotfiles/waybar/launch.sh"), "(re)launch waybar", {})
|
||||
bind.leader_key("CTRL + B", hl.dsp.exec_cmd("~/dotfiles/waybar/toggle.sh"), "toggle waybar", {})
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
||||
@@ -0,0 +1,6 @@
|
||||
local settings = {}
|
||||
|
||||
settings["hostname"] = "arch-c940"
|
||||
settings["profile"] = "laptop"
|
||||
|
||||
return settings
|
||||
Reference in New Issue
Block a user