mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:47:46 +00:00
parent
95055d3a38
commit
0d2602c900
3 changed files with 62 additions and 1 deletions
|
@ -1194,6 +1194,27 @@ String Shell::unescape_token(const String& token)
|
|||
return builder.build();
|
||||
}
|
||||
|
||||
String Shell::find_in_path(const StringView& program_name)
|
||||
{
|
||||
String path = getenv("PATH");
|
||||
if (!path.is_empty()) {
|
||||
auto directories = path.split(':');
|
||||
for (const auto& directory : directories) {
|
||||
Core::DirIterator programs(directory.characters(), Core::DirIterator::SkipDots);
|
||||
while (programs.has_next()) {
|
||||
auto program = programs.next_path();
|
||||
auto program_path = String::formatted("{}/{}", directory, program);
|
||||
if (access(program_path.characters(), X_OK) != 0)
|
||||
continue;
|
||||
if (program == program_name)
|
||||
return program_path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void Shell::cache_path()
|
||||
{
|
||||
if (!m_is_interactive)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue