diff options
author | Andreas Kling <kling@serenityos.org> | 2020-07-07 11:27:35 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-07 11:35:22 +0200 |
commit | 1bc6bb042156d595cf63ed031b142a4ce17afa79 (patch) | |
tree | 90719e8320e77dd8fca104133827acc9e7b06ba1 /Shell/main.cpp | |
parent | 7974279a5d37bec170d5c3fec9a30e76f052df9a (diff) | |
download | serenity-1bc6bb042156d595cf63ed031b142a4ce17afa79.zip |
Shell: Run both /etc/shellrc and ~/.shellrc on startup
The global script runs before the local (per-user) one.
Diffstat (limited to 'Shell/main.cpp')
-rw-r--r-- | Shell/main.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/Shell/main.cpp b/Shell/main.cpp index d08994c3a6..977e9988ad 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -150,22 +150,26 @@ int main(int argc, char** argv) const char* command_to_run = nullptr; const char* file_to_read_from = nullptr; - bool skip_init_file = false; + bool skip_rc_files = false; Core::ArgsParser parser; parser.add_option(command_to_run, "String to read commands from", "command-string", 'c', "command-string"); parser.add_positional_argument(file_to_read_from, "File to read commands from", "file", Core::ArgsParser::Required::No); - parser.add_option(skip_init_file, "Skip running ~/shell-init.sh", "skip-init", 0); + parser.add_option(skip_rc_files, "Skip running shellrc files", "skip-shellrc", 0); parser.parse(argc, argv); - if (!skip_init_file) { - String file_path = Shell::init_file_path; - if (file_path.starts_with('~')) - file_path = shell->expand_tilde(file_path); - if (Core::File::exists(file_path)) { - shell->run_file(file_path, false); - } + if (!skip_rc_files) { + auto run_rc_file = [&](auto& name) { + String file_path = name; + if (file_path.starts_with('~')) + file_path = shell->expand_tilde(file_path); + if (Core::File::exists(file_path)) { + shell->run_file(file_path, false); + } + }; + run_rc_file(Shell::global_init_file_path); + run_rc_file(Shell::local_init_file_path); } if (command_to_run) { |