diff --git a/src/dotfile.cpp b/src/dotfile.cpp index 6a04e33..70d926b 100644 --- a/src/dotfile.cpp +++ b/src/dotfile.cpp @@ -133,6 +133,40 @@ void Dotfile::pull(const std::vector& targets) }); } +void Dotfile::push(const std::vector& targets) +{ + std::vector dotfiles; + std::vector homeFiles; + std::vector systemFiles; + + // Separate home and system targets + 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); + } + else { + homeFiles.push_back(index); + } + }); + + size_t workingDirectory = s_workingDirectory.string().size(); + sync( + dotfiles, homeFiles, systemFiles, + [&workingDirectory](std::string* paths, const std::string& homeFile, const std::string& homeDirectory) { + // homeFile = /home//dotfiles/ + // copy: /home//dotfiles/ -> /home// + paths[0] = homeFile; + paths[1] = homeDirectory + homeFile.substr(workingDirectory); + }, + [&workingDirectory](std::string* paths, const std::string& systemFile) { + // systemFile = /home//dotfiles/ + // copy: /home//dotfiles/ -> + paths[0] = systemFile; + paths[1] = systemFile.substr(workingDirectory); + }); +} + // ----------------------------------------- void Dotfile::sync(const std::vector& paths, const std::vector& homeIndices, const std::vector& systemIndices, diff --git a/src/dotfile.h b/src/dotfile.h index 7643a9d..7597bd9 100644 --- a/src/dotfile.h +++ b/src/dotfile.h @@ -34,6 +34,7 @@ public: void add(const std::vector& targets = {}); void list(const std::vector& targets = {}); void pull(const std::vector& targets = {}); + void push(const std::vector& targets = {}); static void setWorkingDirectory(std::filesystem::path directory) { s_workingDirectory = directory; } static void setSystemDirectories(const std::vector& systemDirectories) { s_systemDirectories = systemDirectories; }