1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 14:25:08 +00:00

Shell: Read and evaluate an init file on start

This behaviour is overridable with the `--skip-init' flag.
The default file is at '~/shell-init.sh'
This commit is contained in:
AnotherTest 2020-06-17 19:37:44 +04:30 committed by Andreas Kling
parent 3d6a035d0f
commit bc3285abb0
4 changed files with 38 additions and 12 deletions

View file

@ -460,6 +460,22 @@ RefPtr<Job> Shell::run_command(AST::Command& command)
return *job;
}
bool Shell::run_file(const String& filename)
{
auto file_result = Core::File::open(filename, Core::File::ReadOnly);
if (file_result.is_error()) {
fprintf(stderr, "Failed to open %s: %s\n", filename.characters(), file_result.error().characters());
return false;
}
auto file = file_result.value();
for (;;) {
auto line = file->read_line(4096);
if (line.is_null())
break;
run_command(String::copy(line, Chomp));
}
return true;
}
void Shell::take_back_stdin()
{
tcsetpgrp(0, m_pid);