mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 21:27:34 +00:00
Shell: Add a not
builtin
`not` just takes a command, runs it, then negates its exit code (0->1, non-zero->0).
This commit is contained in:
parent
2843526513
commit
50473003be
2 changed files with 20 additions and 0 deletions
|
@ -879,6 +879,25 @@ int Shell::builtin_unset(int argc, const char** argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Shell::builtin_not(int argc, const char** argv)
|
||||||
|
{
|
||||||
|
// FIXME: Use ArgsParser when it can collect unrelated -arguments too.
|
||||||
|
if (argc == 1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
AST::Command command;
|
||||||
|
for (size_t i = 1; i < (size_t)argc; ++i)
|
||||||
|
command.argv.append(argv[i]);
|
||||||
|
|
||||||
|
auto commands = expand_aliases({ move(command) });
|
||||||
|
int exit_code = 1;
|
||||||
|
for (auto& job : run_commands(commands)) {
|
||||||
|
block_on_job(job);
|
||||||
|
exit_code = job.exit_code();
|
||||||
|
}
|
||||||
|
return exit_code == 0 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Shell::run_builtin(const AST::Command& command, const NonnullRefPtrVector<AST::Rewiring>& rewirings, int& retval)
|
bool Shell::run_builtin(const AST::Command& command, const NonnullRefPtrVector<AST::Rewiring>& rewirings, int& retval)
|
||||||
{
|
{
|
||||||
if (command.argv.is_empty())
|
if (command.argv.is_empty())
|
||||||
|
|
|
@ -52,6 +52,7 @@
|
||||||
__ENUMERATE_SHELL_BUILTIN(unset) \
|
__ENUMERATE_SHELL_BUILTIN(unset) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(history) \
|
__ENUMERATE_SHELL_BUILTIN(history) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(umask) \
|
__ENUMERATE_SHELL_BUILTIN(umask) \
|
||||||
|
__ENUMERATE_SHELL_BUILTIN(not ) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(dirs) \
|
__ENUMERATE_SHELL_BUILTIN(dirs) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(pushd) \
|
__ENUMERATE_SHELL_BUILTIN(pushd) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(popd) \
|
__ENUMERATE_SHELL_BUILTIN(popd) \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue