Compare commits

..

No commits in common. "ccb2ce3019c6365976ce6de0e33580770a33b3f0" and "34967db7ee689cdef1ac4181c272fdb74ad3486c" have entirely different histories.

2 changed files with 4 additions and 40 deletions

View File

@ -2,52 +2,17 @@ local i_o = require 'i_o'
local pure = require 'pure' local pure = require 'pure'
return function(main_state, config, common, width, point) return function(main_state, config, common, width, point)
local IP_EXE = 'ip'
local TEST_IP = '104.18.114.97' -- ipv4.icanhazip.com
local IP_REGEX = 'via ([^ ]+)'
local DEV_REGEX = 'dev ([^ ]+)'
local ERR = 'Error'
local text_spacing = config.geometry.text_spacing local text_spacing = config.geometry.text_spacing
local __string_match = string.match local __string_match = string.match
i_o.assert_exe_exists(IP_EXE)
-- NOTE conky has a builtin gateway function but it will only output
-- whatever the output of 'ip route' is, which won't pick up changes that
-- some VPNs (like tailscale) will make to the rest of the routing table.
-- More reliable way to test the "default route" is to ask the routing table
-- how it would route to a public IP, which is what we do here.
local ip_cmd = IP_EXE..' route get '..TEST_IP
local get_gateway = function()
local ip_glob = i_o.execute_cmd(ip_cmd)
if ip_glob == nil then
return ERR
else
local ip = __string_match(ip_glob, IP_REGEX)
if ip ~= nil then
return ip
end
local dev = __string_match(ip_glob, DEV_REGEX)
if dev ~= nil then
return dev
end
return ERR
end
end
local mk_stats = function(y) local mk_stats = function(y)
local obj = common.make_text_rows( local obj = common.make_text_rows(
point.x, point.x,
y, y,
width, width,
text_spacing, text_spacing,
-- {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync', 'Gateway'} {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'}
{'Kernel', 'Uptime', 'Last Upgrade', 'Gateway'}
) )
-- just update this once -- just update this once
common.text_rows_set(obj, 1, i_o.conky('$kernel')) common.text_rows_set(obj, 1, i_o.conky('$kernel'))
@ -60,12 +25,11 @@ return function(main_state, config, common, width, point)
"^%d+%s+([^%s]+)%s+([^%s]+).*" "^%d+%s+([^%s]+)%s+([^%s]+).*"
) )
common.text_rows_set(obj, 3, last_update) common.text_rows_set(obj, 3, last_update)
-- common.text_rows_set(obj, 4, last_sync) common.text_rows_set(obj, 4, last_sync)
else else
common.text_rows_set(obj, 3, 'N/A') common.text_rows_set(obj, 3, 'N/A')
-- common.text_rows_set(obj, 4, 'N/A') common.text_rows_set(obj, 4, 'N/A')
end end
common.text_rows_set(obj, 4, get_gateway())
end end
local static = pure.partial(common.text_rows_draw_static, obj) local static = pure.partial(common.text_rows_draw_static, obj)
local dynamic = pure.partial(common.text_rows_draw_dynamic, obj) local dynamic = pure.partial(common.text_rows_draw_dynamic, obj)

View File

@ -274,7 +274,7 @@ M.get_core_topology = function()
pure.partial(gmatch_to_tableN, '(%d+),(%d+)') pure.partial(gmatch_to_tableN, '(%d+),(%d+)')
) )
local out = local out =
i_o.execute_cmd('lscpu -y -p=core,cpu | grep -v \'^#\' | sort -k1,1n -t,') i_o.execute_cmd('lscpu -y -p=core,cpu | grep -v \'^#\' | sort -k1,1n')
return pure.fmap_maybe(f, out) return pure.fmap_maybe(f, out)
end end