diff --git a/CHANGELOG.md b/CHANGELOG.md index 07f021d..36b82da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ - Show indexes on cdr list - `hilbish.messages` interface (details in [#219]) - `hilbish.notification` signal when a message/notification is sent +- `notifyJobFinish` opt to send a notification when background jobs are +completed. [#219]: https://github.com/Rosettea/Hilbish/issues/219 ### Fixed diff --git a/nature/opts/init.lua b/nature/opts/init.lua index 10af1d6..56c34ba 100644 --- a/nature/opts/init.lua +++ b/nature/opts/init.lua @@ -26,7 +26,8 @@ local defaultOpts = { The nice lil shell for {blue}Lua{reset} fanatics! ]], hilbish.user), motd = true, - fuzzy = false + fuzzy = false, + notifyJobFinish = true } for optsName, default in pairs(defaultOpts) do diff --git a/nature/opts/notifyJobFinish.lua b/nature/opts/notifyJobFinish.lua new file mode 100644 index 0000000..a8841a1 --- /dev/null +++ b/nature/opts/notifyJobFinish.lua @@ -0,0 +1,23 @@ +local bait = require 'bait' +local lunacolors = require 'lunacolors' + +bait.catch('job.done', function(job) + if not hilbish.opts.notifyJobFinish then return end + local notifText = string.format(lunacolors.format [[ +Background job with ID#%d has exited (PID %d). +Command string: {bold}{yellow}%s{reset}]], job.id, job.pid, job.cmd) + + if job.stdout ~= '' then + notifText = notifText .. '\n\nStandard output:\n' .. job.stdout + end + if job.stderr ~= '' then + notifText = notifText .. '\n\nStandard error:\n' .. job.stderr + end + + hilbish.messages.send { + channel = 'jobNotify', + title = string.format('Job ID#%d Exited', job.id), + summary = string.format(lunacolors.format 'Background job with command {bold}{yellow}%s{reset} has finished running!', job.cmd), + text = notifText + } +end)