mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:27:45 +00:00
parent
95055d3a38
commit
0d2602c900
3 changed files with 62 additions and 1 deletions
|
@ -1031,6 +1031,43 @@ int Shell::builtin_not(int argc, const char** argv)
|
||||||
return exit_code == 0 ? 1 : 0;
|
return exit_code == 0 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Shell::builtin_kill(int argc, const char** argv)
|
||||||
|
{
|
||||||
|
// Simply translate the arguments and pass them to `kill'
|
||||||
|
Vector<String> replaced_values;
|
||||||
|
auto kill_path = find_in_path("kill");
|
||||||
|
if (kill_path.is_empty()) {
|
||||||
|
warnln("kill: `kill' not found in PATH");
|
||||||
|
return 126;
|
||||||
|
}
|
||||||
|
replaced_values.append(kill_path);
|
||||||
|
for (auto i = 1; i < argc; ++i) {
|
||||||
|
if (auto job_id = resolve_job_spec(argv[i]); job_id.has_value()) {
|
||||||
|
auto job = find_job(job_id.value());
|
||||||
|
if (job) {
|
||||||
|
replaced_values.append(String::number(job->pid()));
|
||||||
|
} else {
|
||||||
|
warnln("kill: Job with pid {} not found", job_id.value());
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
replaced_values.append(argv[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now just run `kill'
|
||||||
|
AST::Command command;
|
||||||
|
command.argv = move(replaced_values);
|
||||||
|
command.position = m_source_position.has_value() ? m_source_position->position : Optional<AST::Position> {};
|
||||||
|
|
||||||
|
auto exit_code = 1;
|
||||||
|
if (auto job = run_command(command)) {
|
||||||
|
block_on_job(job);
|
||||||
|
exit_code = job->exit_code();
|
||||||
|
}
|
||||||
|
return exit_code;
|
||||||
|
}
|
||||||
|
|
||||||
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())
|
||||||
|
|
|
@ -1194,6 +1194,27 @@ String Shell::unescape_token(const String& token)
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String Shell::find_in_path(const StringView& program_name)
|
||||||
|
{
|
||||||
|
String path = getenv("PATH");
|
||||||
|
if (!path.is_empty()) {
|
||||||
|
auto directories = path.split(':');
|
||||||
|
for (const auto& directory : directories) {
|
||||||
|
Core::DirIterator programs(directory.characters(), Core::DirIterator::SkipDots);
|
||||||
|
while (programs.has_next()) {
|
||||||
|
auto program = programs.next_path();
|
||||||
|
auto program_path = String::formatted("{}/{}", directory, program);
|
||||||
|
if (access(program_path.characters(), X_OK) != 0)
|
||||||
|
continue;
|
||||||
|
if (program == program_name)
|
||||||
|
return program_path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
void Shell::cache_path()
|
void Shell::cache_path()
|
||||||
{
|
{
|
||||||
if (!m_is_interactive)
|
if (!m_is_interactive)
|
||||||
|
|
|
@ -46,7 +46,8 @@
|
||||||
__ENUMERATE_SHELL_BUILTIN(fg) \
|
__ENUMERATE_SHELL_BUILTIN(fg) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(bg) \
|
__ENUMERATE_SHELL_BUILTIN(bg) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(wait) \
|
__ENUMERATE_SHELL_BUILTIN(wait) \
|
||||||
__ENUMERATE_SHELL_BUILTIN(dump)
|
__ENUMERATE_SHELL_BUILTIN(dump) \
|
||||||
|
__ENUMERATE_SHELL_BUILTIN(kill)
|
||||||
|
|
||||||
#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 $(...)") \
|
||||||
|
@ -103,6 +104,8 @@ public:
|
||||||
String resolve_path(String) const;
|
String resolve_path(String) const;
|
||||||
String resolve_alias(const String&) const;
|
String resolve_alias(const String&) const;
|
||||||
|
|
||||||
|
static String find_in_path(const StringView& program_name);
|
||||||
|
|
||||||
static bool has_history_event(StringView);
|
static bool has_history_event(StringView);
|
||||||
|
|
||||||
RefPtr<AST::Value> get_argument(size_t);
|
RefPtr<AST::Value> get_argument(size_t);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue