diff --git a/chezmoi/dot_config/river/executable_init b/chezmoi/dot_config/river/executable_init new file mode 100644 index 0000000..a34634f --- /dev/null +++ b/chezmoi/dot_config/river/executable_init @@ -0,0 +1,22 @@ +#! /usr/bin/env lua + + +-- ╭─────────────────────────────────────────────────────────╮ +-- │ Add river config folder to Lua Path │ +-- ╰─────────────────────────────────────────────────────────╯ + +local config_dir = os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME") .. "/.config/" +local river_config_dir = config_dir .. "river/" +package.path = river_config_dir .. '?.lua;' .. river_config_dir .. '?/init.lua;' .. package.path + +local River = require('river') +local Logger = require('logger') + +local logger = Logger:new() +logger:log("Initializing River configuration from Lua") + +local river = River:new() + +river:exec([[riverctl spawn "swaybg -i $HOME/Pictures/Minimalist__cron.png"]]) + +logger:close() diff --git a/chezmoi/dot_config/river/logger.lua b/chezmoi/dot_config/river/logger.lua new file mode 100644 index 0000000..3c282e9 --- /dev/null +++ b/chezmoi/dot_config/river/logger.lua @@ -0,0 +1,48 @@ +--- Logger interface +---@class Logger +---@field available_outputs table Available outputs to use in the logger +---@field output file* The open file to write to +local Logger = { + available_outputs = { + stdout = io.stdout + }, +} + +Logger.__index = Logger + +--- Create a new logger instance +---@param output? file* io.stdout by default, [see Logger.available_outputs](lua://Logger.available_outputs) for possible values +---@return Logger +function Logger:new(output) + local obj = { + output = output or Logger.available_outputs.stdout + } + + setmetatable(obj, self) + self.__index = self + + self:open() + + return obj +end + +function Logger:open() + self:log("\n\n\n") + self:log("Opening logger...") +end + +function Logger:close() + self:log("Closing logger...") + self:log("\n\n\n") + self.output:close() +end + +--- Write data to ouput, it passes the arguments directly to file:write(...) +---@param ... string|number the data to write +function Logger:log(...) + self.output:write(arg) + self.output:write("\n") + self.output:flush() +end + +return Logger diff --git a/chezmoi/dot_config/river/river.lua b/chezmoi/dot_config/river/river.lua new file mode 100644 index 0000000..07e470a --- /dev/null +++ b/chezmoi/dot_config/river/river.lua @@ -0,0 +1,19 @@ +local River = {} + +River.__index = River + +function River:new(new) + local obj = new or {} + + setmetatable(obj, self) + self.__index = self + + return obj +end + +function River:exec(args) + print("Executing: " .. args) + os.execute(args) +end + +return River