/* * Copyright (C) 2021-2022 Riyyi * * SPDX-License-Identifier: MIT */ #ifndef DOTFILE_H #define DOTFILE_H #include // size_t #include #include // function #include #include #include "util/singleton.h" class Dotfile : public Util::Singleton { public: Dotfile(s); virtual ~Dotfile(); enum class SyncType { Pull, Push, }; enum class ExcludeType { File, Directory, EndsWith, }; struct ExcludePath { ExcludeType type; std::string path; }; void add(const std::vector& targets = {}); void list(const std::vector& targets = {}); void pull(const std::vector& targets = {}); void push(const std::vector& targets = {}); void setWorkingDirectory(std::filesystem::path directory) { m_workingDirectory = directory; m_workingDirectorySize = directory.string().size(); } void setSystemDirectories(const std::vector& systemDirectories) { m_systemDirectories = systemDirectories; } void setExcludePaths(const std::vector& excludePaths) { m_excludePaths = excludePaths; } const std::filesystem::path& workingDirectory() const { return m_workingDirectory; } private: void pullOrPush(SyncType type, const std::vector& targets = {}); void sync(SyncType type, const std::vector& paths, const std::vector& homeIndices, const std::vector& systemIndices, const std::function& generateHomePaths, const std::function& generateSystemPaths); void selectivelyCommentOrUncomment(const std::string& path); 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); std::vector m_excludePaths; std::vector m_systemDirectories; std::filesystem::path m_workingDirectory; size_t m_workingDirectorySize { 0 }; }; #endif // DOTFILE_H