Skip to content

Commit

Permalink
Shell: Do not treat the absence of an init script as an error
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpfard authored and awesomekling committed Jul 6, 2020
1 parent e83c36d commit 6d17fe3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Shell/Shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,12 @@ RefPtr<Job> Shell::run_command(AST::Command& command)
return *job;
}

bool Shell::run_file(const String& filename)
bool Shell::run_file(const String& filename, bool explicitly_invoked)
{
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());
if (explicitly_invoked)
fprintf(stderr, "Failed to open %s: %s\n", filename.characters(), file_result.error().characters());
return false;
}
auto file = file_result.value();
Expand Down
2 changes: 1 addition & 1 deletion Shell/Shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Shell : public Core::Object {

int run_command(const StringView&);
RefPtr<Job> run_command(AST::Command&);
bool run_file(const String&);
bool run_file(const String&, bool explicitly_invoked = true);
bool run_builtin(int argc, const char** argv, int& retval);
bool has_builtin(const StringView&) const;
void block_on_job(RefPtr<Job>);
Expand Down
4 changes: 2 additions & 2 deletions Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ int main(int argc, char** argv)
String file_path = Shell::init_file_path;
if (file_path.starts_with('~'))
file_path = shell->expand_tilde(file_path);
if (!shell->run_file(file_path)) {
fprintf(stderr, "Shell: Failed to execute init file '%s'\n", Shell::init_file_path);
if (Core::File::exists(file_path)) {
shell->run_file(file_path, false);
}
}

Expand Down

0 comments on commit 6d17fe3

Please sign in to comment.