diff --git a/Shell/Builtin.cpp b/Shell/Builtin.cpp index fb2734b3e4..0cf26a9542 100644 --- a/Shell/Builtin.cpp +++ b/Shell/Builtin.cpp @@ -64,6 +64,20 @@ int Shell::builtin_alias(int argc, const char** argv) } } else { m_aliases.set(parts[0], parts[1]); + size_t index = 0; + auto match = binary_search( + cached_path.span(), parts[0], [](const String& name, const String& program) -> int { + return strcmp(name.characters(), program.characters()); + }, + &index); + + if (match) + continue; + + while (strcmp(cached_path[index].characters(), parts[0].characters()) < 0) { + index++; + } + cached_path.insert(index, parts[0]); } } diff --git a/Shell/Shell.cpp b/Shell/Shell.cpp index 104b30c4ed..2109ccb1a1 100644 --- a/Shell/Shell.cpp +++ b/Shell/Shell.cpp @@ -388,11 +388,6 @@ String Shell::resolve_alias(const String& name) const bool Shell::is_runnable(const StringView& name) { - // FIXME: for now, check aliases manually because cached path doesn't get - // updated with aliases. Should it? - if (!resolve_alias(name).is_null()) - return true; - if (access(name.to_string().characters(), X_OK) == 0) return true;