update river config

This commit is contained in:
Alexander Navarro 2024-10-30 16:08:52 -03:00
parent ffa2bac00b
commit a3804e67a5
Signed by untrusted user who does not match committer: anavarro
GPG key ID: 6426043E9FA3E3B5
4 changed files with 117 additions and 27 deletions

View file

@ -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
-- ╭─────────────────────────────────────────────────────────╮ config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/river"
-- │ Add river config folder to Lua Path │ 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/" lua "$config_dir"/init.lua
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()

View file

@ -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()

View file

@ -6,6 +6,7 @@ local Logger = {
available_outputs = { available_outputs = {
stdout = io.stdout stdout = io.stdout
}, },
output = io.stdout
} }
Logger.__index = Logger Logger.__index = Logger
@ -27,20 +28,20 @@ function Logger:new(output)
end end
function Logger:open() function Logger:open()
self:log("\n\n\n") self:log("\n\n")
self:log("Opening logger...") self:log("Opening logger...\n")
end end
function Logger:close() function Logger:close()
self:log("Closing logger...") self:log("Closing logger...")
self:log("\n\n\n") self:log("\n\n")
self.output:close() self.output:close()
end end
--- Write data to ouput, it passes the arguments directly to file:write(...) --- Write data to ouput, it passes the arguments directly to file:write(...)
---@param ... string|number the data to write ---@param ... string|number the data to write
function Logger:log(...) function Logger:log(...)
self.output:write(arg) self.output:write(...)
self.output:write("\n") self.output:write("\n")
self.output:flush() self.output:flush()
end end

View file

@ -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.__index = River
--- River class constructor
---@param new? River to override properties
---@return River
function River:new(new) function River:new(new)
local obj = new or {} local obj = new or {}
@ -11,9 +40,41 @@ function River:new(new)
return obj return obj
end end
function River:exec(args) --- Exec an arbitrary system command
print("Executing: " .. args) ---@param cmd string the command to execute
os.execute(args) ---@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 end
return River return River