mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
Utilities: Make ls respect options when specifying more than one path
When specifying more than one path (e.g. with ls -l /usr /bin) ls would ignore other display options and fall back to showing the files in short mode.
This commit is contained in:
parent
161a8ea062
commit
fddcaafe5f
1 changed files with 18 additions and 36 deletions
|
@ -125,49 +125,31 @@ int main(int argc, char** argv)
|
||||||
return do_file_system_object_short(path);
|
return do_file_system_object_short(path);
|
||||||
};
|
};
|
||||||
|
|
||||||
int status = 0;
|
|
||||||
if (paths.is_empty()) {
|
if (paths.is_empty()) {
|
||||||
status = do_file_system_object(".");
|
paths.append(".");
|
||||||
} else if (paths.size() == 1) {
|
|
||||||
status = do_file_system_object(paths[0]);
|
|
||||||
} else {
|
|
||||||
Vector<const char*> directories;
|
|
||||||
Vector<String> names;
|
|
||||||
size_t longest_name = 0;
|
|
||||||
for (auto& path : paths) {
|
|
||||||
if (Core::File::exists(path)) {
|
|
||||||
if (Core::File::is_directory(path)) {
|
|
||||||
directories.append(path);
|
|
||||||
} else {
|
|
||||||
names.append(path);
|
|
||||||
if (names.last().length() > longest_name)
|
|
||||||
longest_name = names.last().length();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
status = do_file_system_object(path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quick_sort(names);
|
quick_sort(paths, [](const String& a, const String& b) {
|
||||||
if (print_names(".", longest_name, names)) {
|
return a < b;
|
||||||
printf("\n");
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (names.size() > 0) {
|
int status = 0;
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
quick_sort(directories, [](String a, String b) { return a < b; });
|
for (size_t i = 0; i < paths.size(); i++) {
|
||||||
for (size_t i = 0; i < directories.size(); ++i) {
|
auto path = paths[i];
|
||||||
auto path = directories.at(i);
|
|
||||||
|
bool show_dir_separator = paths.size() > 1 && Core::File::is_directory(path) && !flag_list_directories_only;
|
||||||
|
if (show_dir_separator) {
|
||||||
printf("%s:\n", path);
|
printf("%s:\n", path);
|
||||||
status = do_file_system_object(path);
|
}
|
||||||
|
auto rc = do_file_system_object(path);
|
||||||
|
if (rc != 0)
|
||||||
|
status = rc;
|
||||||
|
if (show_dir_separator && i != paths.size() - 1) {
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (i < directories.size() - 1) {
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue