From f5e39a64eba779bdfaf4475e9cea0ea024a8032d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 28 May 2025 17:43:01 +1200 Subject: [PATCH] :-'Generic Commit' --- dropshell-build/dropshell-build.sh | 5 +- dropshell-tool/src/BashrcEditor.cpp | 195 +++++++++++++++++----------- dropshell-tool/src/BashrcEditor.hpp | 16 ++- dropshell-tool/src/main.cpp | 12 +- 4 files changed, 141 insertions(+), 87 deletions(-) diff --git a/dropshell-build/dropshell-build.sh b/dropshell-build/dropshell-build.sh index bb522ac..46e689d 100755 --- a/dropshell-build/dropshell-build.sh +++ b/dropshell-build/dropshell-build.sh @@ -202,7 +202,10 @@ function build_arch() { cd "${ARCH_BUILD_DIR}" || exit 1 ninja -j"${JOBS}" - upx "${ARCH_BUILD_DIR}/${EXECUTABLE_NAME}" + if [ "$RELEASE" -eq 1 ]; then + upx "${ARCH_BUILD_DIR}/${EXECUTABLE_NAME}" + fi + if [ ! -d "${OUTPUT_DIR}" ]; then mkdir -p "${OUTPUT_DIR}" fi diff --git a/dropshell-tool/src/BashrcEditor.cpp b/dropshell-tool/src/BashrcEditor.cpp index e6fd836..0f6ac6e 100644 --- a/dropshell-tool/src/BashrcEditor.cpp +++ b/dropshell-tool/src/BashrcEditor.cpp @@ -4,92 +4,133 @@ #include #include #include +#include +#include -std::string removeWhitespace(const std::string& s) { - std::string out; - for (char c : s) { - if (!isspace(static_cast(c))) out += c; +namespace dropshelltool +{ + + static const std::filesystem::path DROPSHELL_RC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc_dropshell_tool"; + static const std::filesystem::path BASHRC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc"; + + std::string removeWhitespace(const std::string &s) + { + std::string out; + for (char c : s) + { + if (!isspace(static_cast(c))) + out += c; + } + return out; } - return out; -} -static constexpr const char* BLOCK_START = "#---DROPSHELL-TOOL-START---"; -static constexpr const char* BLOCK_END = "#---DROPSHELL-TOOL-END---"; + static constexpr const char *BLOCK_START = "#---DROPSHELL-TOOL-START---"; + static constexpr const char *BLOCK_END = "#---DROPSHELL-TOOL-END---"; -BashrcEditor::BashrcEditor(const std::string& bashrcPath) : bashrcPath(bashrcPath) {} + BashrcEditor::BashrcEditor() + { + } -bool BashrcEditor::hasSourceLine(const std::string& scriptPath) const { - std::ifstream infile(bashrcPath); - if (!infile) return false; - std::string line; - bool inBlock = false; - const std::string blockStart = removeWhitespace(BLOCK_START); - const std::string blockEnd = removeWhitespace(BLOCK_END); - const std::string target = "source \"" + scriptPath + "\""; - while (std::getline(infile, line)) { - std::string trimmed = removeWhitespace(line); - if (trimmed == blockStart) { - return true; + bool BashrcEditor::hasSourceLine() const + { + std::ifstream infile(BASHRC_PATH); + if (!infile) + return false; + std::string line; + bool inBlock = false; + const std::string blockStart = removeWhitespace(BLOCK_START); + const std::string blockEnd = removeWhitespace(BLOCK_END); + const std::string target = "source \"" + DROPSHELL_RC_PATH.string() + "\""; + while (std::getline(infile, line)) + { + std::string trimmed = removeWhitespace(line); + if (trimmed == blockStart) + { + return true; + } + } + return false; + } + + void BashrcEditor::addSourceLine() + { + std::ifstream infile(BASHRC_PATH); + std::vector lines; + std::string line; + bool inBlock = false; + const std::string blockStart = removeWhitespace(BLOCK_START); + const std::string blockEnd = removeWhitespace(BLOCK_END); + while (std::getline(infile, line)) + { + std::string trimmed = removeWhitespace(line); + if (trimmed == blockStart) + { + inBlock = true; + continue; + } + if (trimmed == blockEnd) + { + inBlock = false; + continue; + } + if (!inBlock) + { + lines.push_back(line); + } + } + infile.close(); + lines.push_back(BLOCK_START); + lines.push_back("source \"" + DROPSHELL_RC_PATH.string() + "\""); + lines.push_back(BLOCK_END); + std::ofstream outfile(BASHRC_PATH, std::ios::trunc); + for (const auto &l : lines) + { + outfile << l << "\n"; + } + + outfile.close(); + + if (!std::filesystem::exists(DROPSHELL_RC_PATH)) + { + std::filesystem::create_directories(DROPSHELL_RC_PATH.parent_path()); + std::ofstream outfile(DROPSHELL_RC_PATH, std::ios::trunc); + outfile << "echo 'Dropshell tools configured'" << std::endl; + outfile.close(); } } - return false; -} -void BashrcEditor::addSourceLine(const std::string& scriptPath) { - std::ifstream infile(bashrcPath); - std::vector lines; - std::string line; - bool inBlock = false; - const std::string blockStart = removeWhitespace(BLOCK_START); - const std::string blockEnd = removeWhitespace(BLOCK_END); - while (std::getline(infile, line)) { - std::string trimmed = removeWhitespace(line); - if (trimmed == blockStart) { - inBlock = true; - continue; + void BashrcEditor::removeSourceLine() + { + std::ifstream infile(BASHRC_PATH); + std::vector lines; + std::string line; + bool inBlock = false; + const std::string blockStart = removeWhitespace(BLOCK_START); + const std::string blockEnd = removeWhitespace(BLOCK_END); + while (std::getline(infile, line)) + { + std::string trimmed = removeWhitespace(line); + if (trimmed == blockStart) + { + inBlock = true; + continue; + } + if (trimmed == blockEnd) + { + inBlock = false; + continue; + } + if (!inBlock) + { + lines.push_back(line); + } } - if (trimmed == blockEnd) { - inBlock = false; - continue; - } - if (!inBlock) { - lines.push_back(line); + infile.close(); + std::ofstream outfile(BASHRC_PATH, std::ios::trunc); + for (const auto &l : lines) + { + outfile << l << "\n"; } } - infile.close(); - lines.push_back(BLOCK_START); - lines.push_back("source \"" + scriptPath + "\""); - lines.push_back(BLOCK_END); - std::ofstream outfile(bashrcPath, std::ios::trunc); - for (const auto& l : lines) { - outfile << l << "\n"; - } -} -void BashrcEditor::removeSourceLine(const std::string& /*scriptPath*/) { - std::ifstream infile(bashrcPath); - std::vector lines; - std::string line; - bool inBlock = false; - const std::string blockStart = removeWhitespace(BLOCK_START); - const std::string blockEnd = removeWhitespace(BLOCK_END); - while (std::getline(infile, line)) { - std::string trimmed = removeWhitespace(line); - if (trimmed == blockStart) { - inBlock = true; - continue; - } - if (trimmed == blockEnd) { - inBlock = false; - continue; - } - if (!inBlock) { - lines.push_back(line); - } - } - infile.close(); - std::ofstream outfile(bashrcPath, std::ios::trunc); - for (const auto& l : lines) { - outfile << l << "\n"; - } -} \ No newline at end of file +} \ No newline at end of file diff --git a/dropshell-tool/src/BashrcEditor.hpp b/dropshell-tool/src/BashrcEditor.hpp index ce27280..e1390ee 100644 --- a/dropshell-tool/src/BashrcEditor.hpp +++ b/dropshell-tool/src/BashrcEditor.hpp @@ -1,15 +1,17 @@ #pragma once #include +namespace dropshelltool { + class BashrcEditor { public: - BashrcEditor(const std::string& bashrcPath); + BashrcEditor(); // Checks if the unique block with the source line exists - bool hasSourceLine(const std::string& scriptPath) const; + bool hasSourceLine() const; // Adds or updates the unique block with the given scriptPath - void addSourceLine(const std::string& scriptPath); + void addSourceLine(); // Removes the unique block - void removeSourceLine(const std::string& scriptPath); -private: - std::string bashrcPath; -}; \ No newline at end of file + void removeSourceLine(); +}; + +} // namespace dropshelltool \ No newline at end of file diff --git a/dropshell-tool/src/main.cpp b/dropshell-tool/src/main.cpp index fd58827..1317988 100644 --- a/dropshell-tool/src/main.cpp +++ b/dropshell-tool/src/main.cpp @@ -69,13 +69,22 @@ int main(int argc, char* argv[]) { } std::string command = argv[1]; if (command == "install") { + dropshelltool::BashrcEditor bashrcEditor; + bashrcEditor.addSourceLine(); // TODO: Implement install logic using utility classes } else if (command == "publish") { // TODO: Implement publish logic } else if (command == "update") { // TODO: Implement update logic } else if (command == "autocomplete") { - // TODO: Implement autocomplete logic + std::vector args(argv + 2, argv + argc); + if (args.empty()) std::cout << R"(install +publish +update +version +create +help +)"; } else if (command == "version") { std::cout << dropshell::VERSION << std::endl; } else if (command == "create") { @@ -86,7 +95,6 @@ int main(int argc, char* argv[]) { std::cout << " install " << std::endl; std::cout << " publish " << std::endl; std::cout << " update " << std::endl; - std::cout << " autocomplete " << std::endl; std::cout << " version" << std::endl; } else { std::cout << "Unknown command: " << command << std::endl;