feat: add opt to send a notification on job finish

notifications
sammyette 2023-07-10 18:51:25 -04:00
parent f02d4784fb
commit 9113b44a02
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
3 changed files with 27 additions and 1 deletions

View File

@ -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

View File

@ -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

View File

@ -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)