trun

Script for parsing any output. Yes, it is all it does.
git clone git://gtms.dev/trun.git
Log | Files | Refs | README | LICENSE

commit 57d713dd021af5d039683284b365faeab8b09d76
parent bbbe3cea96a74a2971153de823270f2237dc16fb
Author: tms <nemi@skaut.cz>
Date:   Thu,  3 Jun 2021 08:34:36 +0200

Format

Diffstat:
Mtrack_run.lua | 26+++++++++++++++++++-------
Mtrack_run_status.lua | 12++++++++----
2 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/track_run.lua b/track_run.lua @@ -2,16 +2,20 @@ -- <run cmd> | run_track <handler> <name> local handlerName = arg[1] -if not handlerName then error('No handler provided!') end +if not handlerName then + error('No handler provided!') +end local name = arg[2] or 'trun' -local handlerPath = os.getenv('XDG_CONFIG_HOME') .. '/trun/?.lua' +local handlerPath = os.getenv('CONFIG') .. '/trun/?.lua' package.path = package.path .. ';' .. handlerPath local handler = require(handlerName) -- status dir local status_dir = os.getenv('HOME') .. '/.cache/trun' -if not io.open(status_dir) then os.execute('mkdir ' .. status_dir) end +if not io.open(status_dir) then + os.execute('mkdir ' .. status_dir) +end -- status file local status_file = status_dir .. '/' .. name .. '.' .. handlerName @@ -28,7 +32,9 @@ local signal = require 'posix.signal' local function cleanup() os.execute('rm ' .. status_file) - if handler.onEnd then handler.onEnd() end + if handler.onEnd then + handler.onEnd() + end end local function onExit(signum) @@ -49,10 +55,14 @@ local function updateFile(status) file = io.open(status_file, 'w') file:write(status) file:close() - if handler.onUpdate then handler.onUpdate() end + if handler.onUpdate then + handler.onUpdate() + end end -if handler.onStart then handler.onStart() end +if handler.onStart then + handler.onStart() +end local lastStatus for line in io.lines() do @@ -60,7 +70,9 @@ for line in io.lines() do lastStatus = status status = handler.handle(line) - if status and status ~= lastStatus then updateFile(status) end + if status and status ~= lastStatus then + updateFile(status) + end end -- cleanup diff --git a/track_run_status.lua b/track_run_status.lua @@ -1,13 +1,17 @@ #!/usr/bin/env lua local status_dir = os.getenv('HOME') .. '/.cache/trun' -if not io.open(status_dir) then return '' end +if not io.open(status_dir) then + return '' +end local ds = {[0] = 'ffa500', [1] = '00ff00', [-1] = 'ff0000'} local files = {} local list = io.popen('ls ' .. status_dir) -for f in list:lines() do table.insert(files, f) end +for f in list:lines() do + table.insert(files, f) +end local result = {} for _, f in pairs(files) do @@ -20,10 +24,10 @@ for _, f in pairs(files) do table.insert(result, '') else local status = file:read() - table.insert(result, '%{u#' .. ds[tonumber(status)] .. '} ' .. fname .. ' %{u-}') + table.insert(result, '%{F#' .. ds[tonumber(status)] .. '} ' .. fname:upper() .. ' %{F-}') file:close() end end end -print(table.concat(result, '')) +print("[" .. table.concat(result, ',') .. "]")