commit 358c89efad0131acaa283b25393740773ec11e5f
parent f8529aeea1a8164699b1a7b9c7b3f112dd55143d
Author: Tomas Nemec <nemi@skaut.cz>
Date: Mon, 9 Aug 2021 10:23:18 +0200
version: 1.1.3
Add other scripts liek trun-ls and trun-status. Rename print_status to
trun-fmt.
Diffstat:
7 files changed, 133 insertions(+), 77 deletions(-)
diff --git a/README b/README
@@ -1,4 +1,4 @@
-# Track run [v1.1.2 09.08.2021]
+# Track run [v1.1.3 09.08.2021]
TrackRun listen on stdin and for each line it gets status which is written to
status_file.
Status is taken from handler module via `handle` function.
@@ -23,7 +23,9 @@
- handlers/ - real life handlers i use. (contact me to add more)
- TODO
- tools/ - other tools that uses `trun` to make life easier
- - print_status.lua: i use it for show semaphor of cmd (green,orange,red)
+ - trun-fmt.lua: i use it for show semaphor of cmd (green,orange,red)
+ - trun-ls.lua: for list of running trun
+ - trun-status.lua: for status_file content for specific trun
- trun_to_neovim_quickfix.lua: plugin to fill qf-list from cmd
diff --git a/handlers/angulardart.lua b/handlers/angulardart.lua
@@ -2,7 +2,7 @@
-- NOTE: This does not work for `webdev server`
--
-- Status number i use for semaphor in WM status bar.
--- viz->tools/print_status.lua
+-- viz->tools/trun-fmt.lua
--
-- Last output is inside tmpfile so i can load errors to quickfix list
-- inside vim.
diff --git a/tools/print_status.lua b/tools/print_status.lua
@@ -1,73 +0,0 @@
-#!/usr/bin/env lua
-
--- Usage: print_status.lua [<name>]
---
--- Return formatted string for all truns to use inside status bar of your WM.
--- It depends on status codes to be:
--- - `0` - running - orange
--- - `1` - success - green
--- - `-1` - error - red
---
--- You can change colors. viz->#Config
---
--- example output: [%{F#ff0000}NAME%{F-} %{F#00ff00}OTHERNAME%{F-}]
---
--- To get only single trun, add `name` as argument.
---
--- Config
-local status_dir_def = os.getenv('XDG_CACHE_HOME') .. '/trun'
-local status_dir = os.getenv('TRUN_STATUS_DIR') or status_dir_def
--- map status to foreground colors.
-local status_map = {[0] = 'ffa500', [1] = '00ff00', [-1] = 'ff0000'}
----
-
--- silent fail if dir not exists
-if not io.open(status_dir) then
- return ''
-end
-
-local trun_name = arg[1]
-
--- get all status files
-local status_files = {}
-local list = io.popen('ls ' .. status_dir)
-for f in list:lines() do
- table.insert(status_files, f)
-end
-
--- format status_file to string
-local format = function(file, name)
- local output
- if not file then
- table.insert(output, '')
- else
- local status = file:read('*n') -- 'n' means read a number
- local color = status_map[tonumber(status)]
- -- Edit this to your liking
- output = string.format('%%{F#%s} %s %%{F-}', color, name:upper())
- file:close()
- end
- return output
-end
-
-local result = {}
--- For every file fill out results
-for _, status_file_name in ipairs(status_files) do
- local name, _ = status_file_name:match('(.*)%.(.*)')
- if name then
- local status_file_path = status_dir .. '/' .. status_file_name
- local status_file = io.open(status_file_path, 'r')
- if trun_name then
- if name == trun_name then
- table.insert(result, format(status_file, name))
- end
- else
- table.insert(result, format(status_file, name))
- end
- end
-end
-
--- print out results
-if #result > 0 then
- print('[' .. table.concat(result, ',') .. ']')
-end
diff --git a/tools/trun-fmt.lua b/tools/trun-fmt.lua
@@ -0,0 +1,73 @@
+#!/usr/bin/env lua
+
+-- Usage: trun_format.lua [<name>]
+--
+-- Return formatted string for all truns to use inside status bar of your WM.
+-- It depends on status codes to be:
+-- - `0` - running - orange
+-- - `1` - success - green
+-- - `-1` - error - red
+--
+-- You can change colors. viz->#Config
+--
+-- example output: [%{F#ff0000}NAME%{F-} %{F#00ff00}OTHERNAME%{F-}]
+--
+-- To get only single trun, add `name` as argument.
+--
+-- Config
+local status_dir_def = os.getenv('XDG_CACHE_HOME') .. '/trun'
+local status_dir = os.getenv('TRUN_STATUS_DIR') or status_dir_def
+-- map status to foreground colors.
+local status_map = {[0] = 'ffa500', [1] = '00ff00', [-1] = 'ff0000'}
+---
+
+-- silent fail if dir not exists
+if not io.open(status_dir) then
+ return ''
+end
+
+local trun_name = arg[1]
+
+-- get all status files
+local status_files = {}
+local list = io.popen('ls ' .. status_dir)
+for f in list:lines() do
+ table.insert(status_files, f)
+end
+
+-- format status_file to string
+local format = function(file, name)
+ local output
+ if not file then
+ table.insert(output, '')
+ else
+ local status = file:read('*n') -- 'n' means read a number
+ local color = status_map[tonumber(status)]
+ -- Edit this to your liking
+ output = string.format('%%{F#%s} %s %%{F-}', color, name:upper())
+ file:close()
+ end
+ return output
+end
+
+local result = {}
+-- For every file fill out results
+for _, status_file_name in ipairs(status_files) do
+ local name, _ = status_file_name:match('(.*)%.(.*)')
+ if name then
+ local status_file_path = status_dir .. '/' .. status_file_name
+ local status_file = io.open(status_file_path, 'r')
+ if trun_name then
+ if name == trun_name then
+ table.insert(result, format(status_file, name))
+ end
+ else
+ table.insert(result, format(status_file, name))
+ end
+ end
+end
+
+-- print out results
+if #result > 0 then
+ print('[' .. table.concat(result, ',') .. ']')
+end
diff --git a/tools/trun-ls.lua b/tools/trun-ls.lua
@@ -0,0 +1,20 @@
+#!/usr/bin/env lua
+-- list running truns
+--
+-- Usage: trun-ls.lua
+
+-- Config
+local status_dir_def = os.getenv('XDG_CACHE_HOME') .. '/trun'
+local status_dir = os.getenv('TRUN_STATUS_DIR') or status_dir_def
+
+-- silent fail if dir not exists
+if not io.open(status_dir) then
+ return ''
+end
+
+-- get all status files
+local list = io.popen('ls ' .. status_dir)
+for f in list:lines() do
+ print(f)
+end
+
diff --git a/tools/trun-status.lua b/tools/trun-status.lua
@@ -0,0 +1,34 @@
+#!/usr/bin/env lua
+
+-- print content of status_file for trun
+--
+-- Usage: trun-status.lua <name>
+--
+local status_dir_def = os.getenv('XDG_CACHE_HOME') .. '/trun'
+local status_dir = os.getenv('TRUN_STATUS_DIR') or status_dir_def
+
+-- silent fail if dir not exists
+if not io.open(status_dir) then
+ return ''
+end
+
+local trun_name = arg[1]
+
+-- get all status files
+local status_files = {}
+local list = io.popen('ls ' .. status_dir)
+for f in list:lines() do
+ table.insert(status_files, f)
+end
+
+for _, status_file_name in ipairs(status_files) do
+ local name, _ = status_file_name:match('(.*)%.(.*)')
+ if trun_name == name then
+ local status_file_path = status_dir .. '/' .. status_file_name
+ local status_file = io.open(status_file_path, 'r')
+ local status = status_file:read('*a')
+ io.write(status, '\n')
+ else
+ os.exit(1)
+ end
+end
diff --git a/trun.lua b/trun.lua
@@ -1,6 +1,6 @@
#!/usr/bin/env lua
--- Version: 1.1.2 ( 09.08.2021 )
+-- Version: 1.1.3 ( 09.08.2021 )
--
-- Usage
-- <cmd> 1> >(trun <handler> <name>)