mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:27:44 +00:00
Shell: Add a 'setopt' builtin
This builtin sets (and unsets) boolean flags that alter the behaviour of the shell. The only flags added are - inline_exec_keep_empty_segments: Keep empty segments in the result of splitting $(...) by $IFS - verbose: Announce each command before executing it It should be noted that the (rather extreme) verbosity of the names is intentional, and will hopefully be alleviated by the next commit :^)
This commit is contained in:
parent
d6de2b5828
commit
b8d1edb2a2
5 changed files with 66 additions and 3 deletions
|
@ -645,6 +645,45 @@ int Shell::builtin_pwd(int, const char**)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Shell::builtin_setopt(int argc, const char** argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
#define __ENUMERATE_SHELL_OPTION(name, default_, description) \
|
||||
if (options.name) \
|
||||
fprintf(stderr, #name "\n");
|
||||
|
||||
ENUMERATE_SHELL_OPTIONS();
|
||||
|
||||
#undef __ENUMERATE_SHELL_OPTION
|
||||
}
|
||||
|
||||
Core::ArgsParser parser;
|
||||
#define __ENUMERATE_SHELL_OPTION(name, default_, description) \
|
||||
bool name = false; \
|
||||
bool not_##name = false; \
|
||||
parser.add_option(name, "Enable: " description, #name, '\0'); \
|
||||
parser.add_option(not_##name, "Disable: " description, "no_" #name, '\0');
|
||||
|
||||
ENUMERATE_SHELL_OPTIONS();
|
||||
|
||||
#undef __ENUMERATE_SHELL_OPTION
|
||||
|
||||
if (!parser.parse(argc, const_cast<char**>(argv), false))
|
||||
return 1;
|
||||
|
||||
#define __ENUMERATE_SHELL_OPTION(name, default_, description) \
|
||||
if (name) \
|
||||
options.name = true; \
|
||||
if (not_##name) \
|
||||
options.name = false;
|
||||
|
||||
ENUMERATE_SHELL_OPTIONS();
|
||||
|
||||
#undef __ENUMERATE_SHELL_OPTION
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Shell::builtin_time(int argc, const char** argv)
|
||||
{
|
||||
Vector<const char*> args;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue