mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
Shell: Add support for special parameter that expands to return-code of last program executed
This commit is contained in:
parent
2bd181a14b
commit
91a609d945
Notes:
sideshowbarker
2024-07-19 12:10:29 +09:00
Author: https://github.com/MinusGix Commit: https://github.com/SerenityOS/serenity/commit/91a609d9454 Pull-request: https://github.com/SerenityOS/serenity/pull/537 Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/bugaevc
2 changed files with 5 additions and 0 deletions
|
@ -14,6 +14,7 @@ struct GlobalState {
|
|||
struct termios termios;
|
||||
bool was_interrupted { false };
|
||||
bool was_resized { false };
|
||||
int last_return_code { 0 };
|
||||
};
|
||||
|
||||
extern GlobalState g;
|
||||
|
|
|
@ -307,6 +307,8 @@ static Vector<String> expand_parameters(const StringView& param)
|
|||
return { param };
|
||||
|
||||
String variable_name = String(param.substring_view(1, param.length() - 1));
|
||||
if (variable_name == "?")
|
||||
return { String::number(g.last_return_code) };
|
||||
|
||||
char* env_value = getenv(variable_name.characters());
|
||||
if (env_value == nullptr)
|
||||
|
@ -546,6 +548,8 @@ static int run_command(const String& cmd)
|
|||
}
|
||||
}
|
||||
|
||||
g.last_return_code = return_value;
|
||||
|
||||
// FIXME: Should I really have to tcsetpgrp() after my child has exited?
|
||||
// Is the terminal controlling pgrp really still the PGID of the dead process?
|
||||
tcsetpgrp(0, getpid());
|
||||
|
|
Loading…
Add table
Reference in a new issue