conky-config/conky.conf

153 lines
4.2 KiB
Plaintext

--------------------------------------------------------------------------------
-- Loading Sequence Overview
--
-- Since this is the most over-engineered conky config ever (actually probably),
-- here are the approximate loading steps:
--
-- 1. bootstrap (this file)
-- 1. set up paths
-- 2. find valid config (a yaml file, see convoluted reasoning below)
-- 3. set up conky variables
-- 2. run startup hook which does some insane dark magic including
-- 1. arranging all modules on the screen
-- 2. 'compiling' super fast functions that don't make computer lag
-- 3. pre-drawing all the crap that doesn't change
-- 4. checking various paths/exes so things don't crash for unknown reasons
-- 3. run main loop
--
-- NOTE: For all brave souls/AIs trying to understand this program, the biggest
-- 'hack' is the fact that this file (conky.conf) is actually not really a
-- config file. The 'real' config file is a yaml file which is validated
-- using a yaml schema. This file is effectively a bootstrap file, but it is
-- not meant to be 'configured' when migrating to a new machine.
--
-- Why bother doing this? Because I got tired of hacking my hard-coded config
-- when switching to different machines.
--------------------------------------------------------------------------------
-- set up paths
local conky_dir = debug.getinfo(1).source:match("@?(.*/)")
local subdirs = {
'src/?.lua',
'src/modules/?.lua',
'src/widget/?.lua',
'src/widget/arc/?.lua',
'src/widget/text/?.lua',
'src/widget/timeseries/?.lua',
'src/widget/rect/?.lua',
'src/widget/line/?.lua',
'lib/share/lua/5.4/?.lua',
'lib/share/lua/5.4/?/init.lua',
}
for i = 1, #subdirs do
subdirs[i] = conky_dir..subdirs[i]
end
package.path = table.concat(subdirs, ';')
package.cpath = conky_dir..'lib/lib/lua/5.4/?.so;'
--------------------------------------------------------------------------------
-- select global config to use (fallback to default if none found)
local yaml = require 'lyaml'
local i_o = require 'i_o'
-- local schema_path = conky_dir..'/config/schema.yml'
-- local validate_config
-- if i_o.exe_exists('yajsv') then
-- validate_config = function(config_path)
-- local cmd = string.format('yajsv -q -s %s %s', schema_path, config_path)
-- return i_o.exit_code_cmd(cmd) == 0
-- end
-- else
-- validate_config = function(_)
-- i_o.warnf('could not validate config')
-- return true
-- end
-- end
local config_path = '/tmp/conky.yml'
local try_read_config = function(path)
local cmd = string.format('dhall-to-yaml --file %s > %s', path, config_path)
return i_o.exit_code_cmd(cmd)
end
local find_valid_config = function(paths)
for i = 1, #paths do
local path = paths[i]
local rc = try_read_config(path)
if rc == 0 then
i_o.infof('Using config at %s', path)
return yaml.load(i_o.read_file(config_path))
else
i_o.warnf('could not read %s; trying next', path)
end
end
i_o.assertf(false, 'could not load valid config')
end
local get_config_dir = function()
return (os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME")..'/.config')..'/'
end
local try_config_paths = {
get_config_dir()..'conky.dhall',
conky_dir..'config/fallback.dhall'
}
local config = find_valid_config(try_config_paths)
local bootstrap = config.bootstrap
local startup_hook = string.format(
'start %f %s %s %s',
bootstrap.update_interval,
config_path,
package.path,
package.cpath
)
conky.config = {
background = false,
-- adjust cpu dial sensitivity (1-14)
cpu_avg_samples = 4,
net_avg_samples = 1,
out_to_console = false,
own_window = true,
own_window_type = 'override',
own_window_transparent = true,
own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
xinerama_head = 0,
double_buffer = true,
minimum_width = bootstrap.dimensions.x,
minimum_height = bootstrap.dimensions.y,
draw_shades = false,
draw_outline = false,
draw_borders = false,
gap_x = 0,
gap_y = 0,
alignment = 'top_left',
no_buffers = true,
-- Lua Load
lua_load = conky_dir..'main.lua',
lua_draw_hook_post = 'main',
lua_startup_hook = startup_hook
}
--control updates entirely in lua
conky.text = [[]]