mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:27:43 +00:00
Shell: Add the `wait' builtin
This builtin...waits...for the jobs it's given (or all the existing jobs).
This commit is contained in:
parent
607931268e
commit
71bb62d03c
2 changed files with 40 additions and 1 deletions
|
@ -743,6 +743,44 @@ int Shell::builtin_umask(int argc, const char** argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Shell::builtin_wait(int argc, const char** argv)
|
||||||
|
{
|
||||||
|
Vector<const char*> job_ids;
|
||||||
|
|
||||||
|
Core::ArgsParser parser;
|
||||||
|
parser.add_positional_argument(job_ids, "Job IDs to wait for, defaults to all jobs if missing", "jobs", Core::ArgsParser::Required::No);
|
||||||
|
|
||||||
|
if (!parser.parse(argc, const_cast<char**>(argv), false))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
Vector<NonnullRefPtr<Job>> jobs_to_wait_for;
|
||||||
|
|
||||||
|
if (job_ids.is_empty()) {
|
||||||
|
for (auto it : jobs)
|
||||||
|
jobs_to_wait_for.append(it.value);
|
||||||
|
} else {
|
||||||
|
for (String id_s : job_ids) {
|
||||||
|
auto id_opt = id_s.to_uint();
|
||||||
|
if (id_opt.has_value()) {
|
||||||
|
if (auto job = find_job(id_opt.value())) {
|
||||||
|
jobs_to_wait_for.append(*job);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
warnln("wait: invalid or nonexistent job id {}", id_s);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& job : jobs_to_wait_for) {
|
||||||
|
job->set_running_in_background(false);
|
||||||
|
block_on_job(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int Shell::builtin_unset(int argc, const char** argv)
|
int Shell::builtin_unset(int argc, const char** argv)
|
||||||
{
|
{
|
||||||
Vector<const char*> vars;
|
Vector<const char*> vars;
|
||||||
|
|
|
@ -58,7 +58,8 @@
|
||||||
__ENUMERATE_SHELL_BUILTIN(jobs) \
|
__ENUMERATE_SHELL_BUILTIN(jobs) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(disown) \
|
__ENUMERATE_SHELL_BUILTIN(disown) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(fg) \
|
__ENUMERATE_SHELL_BUILTIN(fg) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(bg)
|
__ENUMERATE_SHELL_BUILTIN(bg) \
|
||||||
|
__ENUMERATE_SHELL_BUILTIN(wait)
|
||||||
|
|
||||||
#define ENUMERATE_SHELL_OPTIONS() \
|
#define ENUMERATE_SHELL_OPTIONS() \
|
||||||
__ENUMERATE_SHELL_OPTION(inline_exec_keep_empty_segments, false, "Keep empty segments in inline execute $(...)") \
|
__ENUMERATE_SHELL_OPTION(inline_exec_keep_empty_segments, false, "Keep empty segments in inline execute $(...)") \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue