From f57d0ad239c0c466f19e2d4d40d2a9cc2be5da4f Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 22 Jun 2025 13:06:35 +1200 Subject: [PATCH] 'Generic Commit' --- getpkg/src/main.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/getpkg/src/main.cpp b/getpkg/src/main.cpp index 345e28e..964f8ba 100644 --- a/getpkg/src/main.cpp +++ b/getpkg/src/main.cpp @@ -656,9 +656,10 @@ int clean_tool(int argc, char* argv[]) { } } - // Step 4: Clean up autocomplete entries in ~/.bashrc_getpkg + // Step 4: Clean up autocomplete entries and obsolete PATH exports in ~/.bashrc_getpkg DropshellScriptManager scriptManager; int autocompleteCleaned = 0; + int pathEntriesRemoved = 0; std::filesystem::path bashrcPath = std::filesystem::path(home) / ".bashrc_getpkg"; if (std::filesystem::exists(bashrcPath)) { std::ifstream infile(bashrcPath); @@ -668,6 +669,22 @@ int clean_tool(int argc, char* argv[]) { std::string currentTool = ""; while (std::getline(infile, line)) { + // Check for obsolete PATH exports (we use symlinks now, not PATH modifications) + if (line.find("export PATH=") != std::string::npos && line.find("/.local/bin/getpkg/") != std::string::npos) { + // Extract tool name from the PATH line + size_t toolStart = line.find("/.local/bin/getpkg/"); + if (toolStart != std::string::npos) { + toolStart += strlen("/.local/bin/getpkg/"); + size_t toolEnd = line.find(":", toolStart); + if (toolEnd != std::string::npos) { + std::string toolInPath = line.substr(toolStart, toolEnd - toolStart); + std::cout << "Removing obsolete PATH entry for: " << toolInPath << std::endl; + pathEntriesRemoved++; + continue; // Skip this line + } + } + } + // Check for autocomplete block start if (line.find("# GETPKG-AUTOCOMPLETE-START: ") != std::string::npos) { currentTool = line.substr(line.find(": ") + 2); @@ -705,7 +722,7 @@ int clean_tool(int argc, char* argv[]) { infile.close(); // Write back the cleaned file if we removed anything - if (autocompleteCleaned > 0) { + if (autocompleteCleaned > 0 || pathEntriesRemoved > 0) { std::ofstream outfile(bashrcPath, std::ios::trunc); for (const auto& l : lines) { outfile << l << "\n"; @@ -732,6 +749,7 @@ int clean_tool(int argc, char* argv[]) { std::cout << " - Removed " << danglingSymlinksRemoved << " dangling symlinks" << std::endl; std::cout << " - Removed " << nonSymlinksRemoved << " non-symlinks from ~/.local/bin/getpkg" << std::endl; std::cout << " - Cleaned " << autocompleteCleaned << " autocomplete entries" << std::endl; + std::cout << " - Removed " << pathEntriesRemoved << " obsolete PATH entries" << std::endl; std::cout << " - Removed " << emptyDirsRemoved << " empty directories" << std::endl; return 0;