diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-06-17 19:37:44 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-05 15:43:14 +0200 |
commit | bc3285abb02c13918cf2653deb39dd9c9d71c202 (patch) | |
tree | 0d7571952661133f3c47e5eaeb90f0dbcdcb76ac /Shell/Shell.cpp | |
parent | 3d6a035d0f2b8022ce7026c675ab395d30d2582c (diff) | |
download | serenity-bc3285abb02c13918cf2653deb39dd9c9d71c202.zip |
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'
Diffstat (limited to 'Shell/Shell.cpp')
-rw-r--r-- | Shell/Shell.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index b6ce3d8437..ac945dd893 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -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); |