mirror of
https://github.com/Hilbis/Hilbish
synced 2025-03-13 18:00:41 +00:00
to write output, you would usually just use the print builtin since commanders are just lua custom commands but this does not consider the fact of pipes or other shell operators being used to redirect or whatever. this adds readable/writable "sinks" which is a type for input or output and is currently only used for commanders but can be used for other hilbish things in the future
26 lines
496 B
Lua
26 lines
496 B
Lua
local commander = require 'commander'
|
|
|
|
commander.register('disown', function(args, sinks)
|
|
if #hilbish.jobs.all() == 0 then
|
|
sinks.out:writeln 'disown: no current job'
|
|
return 1
|
|
end
|
|
|
|
local id
|
|
if #args < 0 then
|
|
id = tonumber(args[1])
|
|
if not id then
|
|
sinks.out:writeln 'disown: invalid id for job'
|
|
return 1
|
|
end
|
|
else
|
|
id = hilbish.jobs.last().id
|
|
end
|
|
|
|
local ok = pcall(hilbish.jobs.disown, id)
|
|
if not ok then
|
|
sinks.out:writeln 'disown: job does not exist'
|
|
return 2
|
|
end
|
|
end)
|