mirror of https://github.com/Hilbis/Hilbish
feat: job enhancements (#153)
* feat: add hilbish.job.add function this is mainly to accomodate for the employer handler (#152) * feat!: add start function to jobs the commit itself adds a few things but the main purpose is to facilitate a lua side start function that can restart the job there is a breaking change in the hilbish.job.add function; it is now required to provide an extra table for arguments, since the first cmd table isnt really what's actually ran * fix: reuse standard files for jobs * fix: deadlock in lua job add function and not taking proper amount of args * fix: assign binary path to job * feat: emit job.add hook when job is added * chore: update modules * fix: use setpgid on cmd procattr for background jobs * fix: use right procattr on correct os * fix: set bg proc attr in build tagged file * feat: add disown function * fix: stop jobs on exit * feat: add disown command * feat: add jobs.last function to get last job * feat: make disown command get last job if id isnt suppied as arg * chore: remove unused code * feat: add job output * chore: fix comments * fix!: make exec path in job add explicit in lua side * docs: add docs and changelogs relating to jobsfg-job
parent
392cb66382
commit
d2f16dfbbf
@ -0,0 +1,40 @@
|
||||
Hilbish has pretty standard job control. It's missing one or two things,
|
||||
but works well. One thing which is different from other shells
|
||||
(besides Hilbish) itself is the API for jobs, and of course it's in Lua.
|
||||
You can add jobs, stop and delete (disown) them and even get output.
|
||||
|
||||
# Job Interface
|
||||
The job interface refers to `hilbish.jobs`.
|
||||
## Functions
|
||||
(Note that in the list here, they're called from `hilbish.jobs`, so
|
||||
a listing of `foo` would mean `hilbish.jobs.foo`)
|
||||
|
||||
- `all()` -> {jobs}: Returns a table of all jobs.
|
||||
- `last()` -> job: Returns the last added job.
|
||||
- `get(id)` -> job: Get a job by its ID.
|
||||
- `add(cmdstr, args, execPath)` -> job: Adds a new job to the job table.
|
||||
Note that this does not run the command; You have to start it manually.
|
||||
`cmdstr` is the user's input for the job, `args` is a table of arguments
|
||||
for the command. It includes arg0 (don't set it as entry 0 in the table)
|
||||
and `execPath` is an absolute path for the command executable.
|
||||
- `disown(id)`: Removes a job by ID from the job table.
|
||||
|
||||
# Job Object
|
||||
A job object on the Lua side is a table with some functions.
|
||||
On the under side it represents a job in the job table.
|
||||
You can still have a job object for a disowned job,
|
||||
it just won't be *working* anywhere. :^)
|
||||
|
||||
## Properties
|
||||
- `cmd`: command string
|
||||
- `running`: boolean whether the job is running
|
||||
- `id`: unique id for the job
|
||||
- `pid`: process id for the job
|
||||
- `exitCode`: exit code of the job
|
||||
In ordinary cases you'd prefer to use the `id` instead of `pid`.
|
||||
The `id` is unique to Hilbish and is how you get jobs with the
|
||||
`hilbish.jobs` interface. It may also not describe the job entirely.
|
||||
|
||||
## Functions
|
||||
- `stop()`: Stops the job.
|
||||
- `start()`: Starts the job.
|
@ -0,0 +1,25 @@
|
||||
local commander = require 'commander'
|
||||
|
||||
commander.register('disown', function(args)
|
||||
if #hilbish.jobs.all() == 0 then
|
||||
print 'disown: no current job'
|
||||
return 1
|
||||
end
|
||||
|
||||
local id
|
||||
if #args < 0 then
|
||||
id = tonumber(args[1])
|
||||
if not id then
|
||||
print '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
|
||||
print 'disown: job does not exist'
|
||||
return 2
|
||||
end
|
||||
end)
|
Loading…
Reference in new issue