Skip to content

Commit 0b1ea13

Browse files
committed
script: try multiple locatons
specifically, try in the hack path, in the hack path parent directory, and in the CWD, in that order
1 parent 0413b71 commit 0b1ea13

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

library/Core.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,22 @@ bool Core::loadScriptFile(color_ostream &out, std::filesystem::path fname, bool
859859
INFO(script,out) << "Running script: " << fname << std::endl;
860860
std::cerr << "Running script: " << fname << std::endl;
861861
}
862-
std::ifstream script{ fname.c_str() };
862+
863+
auto pathlist = {getHackPath(), getHackPath().parent_path(), std::filesystem::current_path()};
864+
865+
std::filesystem::path path;
866+
867+
for (auto& p : pathlist)
868+
{
869+
auto candidate = fname.is_relative() ? p / fname : fname;
870+
if (std::filesystem::exists(candidate))
871+
{
872+
path = candidate;
873+
break;
874+
}
875+
}
876+
877+
std::ifstream script{ path };
863878
if ( !script )
864879
{
865880
if(!silent)

0 commit comments

Comments
 (0)