Manager: Add target filtering to Dotfile::list()

This commit is contained in:
Riyyi
2021-09-20 18:18:31 +02:00
parent 1893f08ea8
commit f8ccfe79b8
2 changed files with 17 additions and 2 deletions
+15 -1
View File
@@ -26,7 +26,7 @@ Dotfile::~Dotfile()
// -----------------------------------------
void Dotfile::list()
void Dotfile::list(const std::vector<std::string>& targets)
{
if (s_workingDirectory.empty()) {
fprintf(stderr, "\033[31;1mDotfile:\033[0m working directory is unset\n");
@@ -43,6 +43,9 @@ void Dotfile::list()
if (path.is_directory() || filter(path)) {
continue;
}
if (!targets.empty() && !include(path.path().string(), targets)) {
continue;
}
printf("%s\n", path.path().c_str() + workingDirectory);
}
}
@@ -72,4 +75,15 @@ bool Dotfile::filter(const std::filesystem::path& path)
return false;
}
bool Dotfile::include(const std::filesystem::path& path, const std::vector<std::string>& targets)
{
for (const auto& target : targets) {
if (path.string().find(s_workingDirectory / target) == 0) {
return true;
}
}
return false;
}
} // namespace Util