diff --git a/chezmoi/dot_config/river/executable_init b/chezmoi/dot_config/river/executable_init index a34634f..4f28cd0 100644 --- a/chezmoi/dot_config/river/executable_init +++ b/chezmoi/dot_config/river/executable_init @@ -1,22 +1,10 @@ -#! /usr/bin/env lua +#!/usr/bin/env bash +# Wrapper for launching the configuration from lua. This will add the river +# directory to the LUA_PATH global variable so the configuration can be +# splitted into multiple files --- ╭─────────────────────────────────────────────────────────╮ --- │ Add river config folder to Lua Path │ --- ╰─────────────────────────────────────────────────────────╯ +config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/river" +export LUA_PATH="$config_dir/?.lua;$config_dir/?/init.lua;$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() +lua "$config_dir"/init.lua diff --git a/chezmoi/dot_config/river/init.lua b/chezmoi/dot_config/river/init.lua new file mode 100644 index 0000000..cd73a7c --- /dev/null +++ b/chezmoi/dot_config/river/init.lua @@ -0,0 +1,40 @@ +local River = require('river') +local Logger = require('logger') + +local logger = Logger:new() +logger:log( + [[ + +---------------------------------------------------------+ + | Initializing River... | + +---------------------------------------------------------+ + ]] +) + +local config = { + +} + +local river = River:new() +print(type(river)) + +river:set_bg("$HOME/Pictures/Minimalist__cron.png") + +-- ╭─────────────────────────────────────────────────────────╮ +-- │ Keymaps │ +-- ╰─────────────────────────────────────────────────────────╯ + +local mods = river.keys.modifiers +river:map { mods.super, "Return", "spawn kitty" } +river:map { mods.super_shift, "q", "exit" } + +-- river:exec("rivertile -view-padding 2 -outer-padding 2 -main-ratio 0.5 -main-count 1 &") + +local cmds = { + "waybar", +} + +for _, cmd in ipairs(cmds) do + river:spawn(cmd) +end + +logger:close() diff --git a/chezmoi/dot_config/river/logger.lua b/chezmoi/dot_config/river/logger.lua index 3c282e9..4f43c93 100644 --- a/chezmoi/dot_config/river/logger.lua +++ b/chezmoi/dot_config/river/logger.lua @@ -6,6 +6,7 @@ local Logger = { available_outputs = { stdout = io.stdout }, + output = io.stdout } Logger.__index = Logger @@ -27,20 +28,20 @@ function Logger:new(output) end function Logger:open() - self:log("\n\n\n") - self:log("Opening logger...") + self:log("\n\n") + self:log("Opening logger...\n") end function Logger:close() self:log("Closing logger...") - self:log("\n\n\n") + self:log("\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(...) self.output:write("\n") self.output:flush() end diff --git a/chezmoi/dot_config/river/river.lua b/chezmoi/dot_config/river/river.lua index 07e470a..5cbc9e4 100644 --- a/chezmoi/dot_config/river/river.lua +++ b/chezmoi/dot_config/river/river.lua @@ -1,7 +1,36 @@ -local River = {} +---@enum Modifiers +local modifiers = { + super = "Super ", + ctrl = "Control ", + shift = "Shift ", + alt = "Alt ", + + super_shift = "Super+Shift ", + super_ctrl = "Super+Control ", + super_ctrl_shift = "Super+Control+Shift ", + + ctrl_shift = "Control+Shift ", + + none = "None ", +} + + +--- Wrapper around the riverctl cmd +---@class River +local River = { + cmds = { + background = "swaybg -i %s" + }, + keys = { + modifiers = modifiers + } +} River.__index = River +--- River class constructor +---@param new? River to override properties +---@return River function River:new(new) local obj = new or {} @@ -11,9 +40,41 @@ function River:new(new) return obj end -function River:exec(args) - print("Executing: " .. args) - os.execute(args) +--- Exec an arbitrary system command +---@param cmd string the command to execute +---@private +---@return string? +function River:exec(cmd) + os.execute(cmd) +end + +--- Execute the given command with riverctl spawn +---@param cmd string the command to execute +function River:spawn(cmd) + self:exec(string.format([[riverctl spawn "%s"]], cmd)) +end + +--- Set a new wallpaper with the default cmds.background +---@param path string The path to the image +function River:set_bg(path) + self:spawn(string.format(self.cmds.background, path)) +end + +---@class MapArgs +---@field [1] Modifiers The modifier to use +---@field [2] string +---@field [3] string +---@field mode? ("normal"|"locked")[], } + +--- Create a new mapping +--- @param args MapArgs +function River:map(args) + local modes = args.mode or { "normal" } + + for _, mode in ipairs(modes) do + local map = string.format([[riverctl map %s %s %s %s]], mode, args[1], args[2], args[3]) + self:exec(map) + end end return River