diff --git a/src/dotfile.cpp b/src/dotfile.cpp index e477f0e..0ccbdeb 100644 --- a/src/dotfile.cpp +++ b/src/dotfile.cpp @@ -93,7 +93,8 @@ void Dotfile::list(const std::vector& targets) return; } - forEachDotfile(targets, [](std::filesystem::directory_entry path, size_t, size_t workingDirectory) { + size_t workingDirectory = s_workingDirectory.string().size(); + forEachDotfile(targets, [&workingDirectory](std::filesystem::directory_entry path, size_t) { printf("%s\n", path.path().c_str() + workingDirectory + 1); }); } @@ -105,7 +106,7 @@ void Dotfile::pull(const std::vector& targets) std::vector systemFiles; // Separate home and system targets - forEachDotfile(targets, [&](const std::filesystem::directory_entry& path, size_t index, size_t) { + forEachDotfile(targets, [&](const std::filesystem::directory_entry& path, size_t index) { dotfiles.push_back(path.path().string()); if (isSystemTarget(path.path().string())) { systemFiles.push_back(index); @@ -208,10 +209,8 @@ void Dotfile::sync(const std::vector& paths, const std::vector& targets, const std::function& callback) +void Dotfile::forEachDotfile(const std::vector& targets, const std::function& callback) { - size_t workingDirectory = s_workingDirectory.string().size(); - size_t index = 0; for (const auto& path : std::filesystem::recursive_directory_iterator { s_workingDirectory }) { if (path.is_directory() || filter(path)) { @@ -220,7 +219,7 @@ void Dotfile::forEachDotfile(const std::vector& targets, const std: if (!targets.empty() && !include(path.path().string(), targets)) { continue; } - callback(path, index++, workingDirectory); + callback(path, index++); } } diff --git a/src/dotfile.h b/src/dotfile.h index 5b3f853..7643a9d 100644 --- a/src/dotfile.h +++ b/src/dotfile.h @@ -43,7 +43,7 @@ private: void sync(const std::vector& paths, const std::vector& homeIndices, const std::vector& systemIndices, const std::function& generateHomePaths, const std::function& generateSystemPaths); - void forEachDotfile(const std::vector& targets, const std::function& callback); + void forEachDotfile(const std::vector& targets, const std::function& callback); bool filter(const std::filesystem::path& path); bool include(const std::filesystem::path& path, const std::vector& targets); bool isSystemTarget(const std::string& target);