1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 10:25:10 +00:00

Shell: highlight runnable commands

And display in red the command which will result in something like "no
command, or is directory" (inspired by the fish shell).
This commit is contained in:
Mathieu PATUREL 2020-08-03 10:04:27 +10:00 committed by Andreas Kling
parent e799da1fb6
commit 2b4b9d212e
3 changed files with 23 additions and 1 deletions

View file

@ -386,6 +386,21 @@ String Shell::resolve_alias(const String& name) const
return m_aliases.get(name).value_or({});
}
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;
return !!binary_search(cached_path.span(), name.to_string(), [](const String& name, const String& program) -> int {
return strcmp(name.characters(), program.characters());
});
}
int Shell::run_command(const StringView& cmd)
{
if (cmd.is_empty())