From 8e973c0479b22ba2c65758be7ca2ccd8b3e1be14 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Fri, 23 Feb 2024 20:20:02 -0500 Subject: [PATCH 1/3] ADD gateway --- src/modules/system.lua | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/modules/system.lua b/src/modules/system.lua index ddda7c1..e0e7e3f 100644 --- a/src/modules/system.lua +++ b/src/modules/system.lua @@ -2,17 +2,52 @@ local i_o = require 'i_o' local pure = require 'pure' 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 __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 obj = common.make_text_rows( point.x, y, width, text_spacing, - {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync'} + -- {'Kernel', 'Uptime', 'Last Upgrade', 'Last Sync', 'Gateway'} + {'Kernel', 'Uptime', 'Last Upgrade', 'Gateway'} ) -- just update this once common.text_rows_set(obj, 1, i_o.conky('$kernel')) @@ -25,11 +60,12 @@ return function(main_state, config, common, width, point) "^%d+%s+([^%s]+)%s+([^%s]+).*" ) 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 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 + common.text_rows_set(obj, 4, get_gateway()) end local static = pure.partial(common.text_rows_draw_static, obj) local dynamic = pure.partial(common.text_rows_draw_dynamic, obj) From ec1e22652f792295d2175b9a712795c6bc5d1eee Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Wed, 6 Mar 2024 12:23:49 -0500 Subject: [PATCH 2/3] FIX sort for some cpu topologies --- src/sys.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sys.lua b/src/sys.lua index 8788af6..ec41dfd 100644 --- a/src/sys.lua +++ b/src/sys.lua @@ -274,7 +274,8 @@ M.get_core_topology = function() pure.partial(gmatch_to_tableN, '(%d+),(%d+)') ) local out = - i_o.execute_cmd('lscpu -y -p=core,cpu | grep -v \'^#\' | sort -k1,1n') + i_o.execute_cmd('lscpu -y -p=core,cpu | grep -v \'^#\' | sort -k1,1n -t,') + print(out) return pure.fmap_maybe(f, out) end From c7e3bdced29fdde98e4f11f2c26ebbf549e8147e Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Fri, 12 Jul 2024 12:39:55 -0400 Subject: [PATCH 3/3] FIX remove useless print --- src/sys.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/src/sys.lua b/src/sys.lua index ec41dfd..f5d436e 100644 --- a/src/sys.lua +++ b/src/sys.lua @@ -275,7 +275,6 @@ M.get_core_topology = function() ) local out = i_o.execute_cmd('lscpu -y -p=core,cpu | grep -v \'^#\' | sort -k1,1n -t,') - print(out) return pure.fmap_maybe(f, out) end