'Generic Commit'
All checks were successful
Build-Test-Publish / build (linux/amd64) (push) Successful in 43s
Build-Test-Publish / build (linux/arm64) (push) Successful in 56s

This commit is contained in:
Your Name 2025-06-22 13:06:35 +12:00
parent 84cda8039a
commit f57d0ad239

View File

@ -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; DropshellScriptManager scriptManager;
int autocompleteCleaned = 0; int autocompleteCleaned = 0;
int pathEntriesRemoved = 0;
std::filesystem::path bashrcPath = std::filesystem::path(home) / ".bashrc_getpkg"; std::filesystem::path bashrcPath = std::filesystem::path(home) / ".bashrc_getpkg";
if (std::filesystem::exists(bashrcPath)) { if (std::filesystem::exists(bashrcPath)) {
std::ifstream infile(bashrcPath); std::ifstream infile(bashrcPath);
@ -668,6 +669,22 @@ int clean_tool(int argc, char* argv[]) {
std::string currentTool = ""; std::string currentTool = "";
while (std::getline(infile, line)) { 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 // Check for autocomplete block start
if (line.find("# GETPKG-AUTOCOMPLETE-START: ") != std::string::npos) { if (line.find("# GETPKG-AUTOCOMPLETE-START: ") != std::string::npos) {
currentTool = line.substr(line.find(": ") + 2); currentTool = line.substr(line.find(": ") + 2);
@ -705,7 +722,7 @@ int clean_tool(int argc, char* argv[]) {
infile.close(); infile.close();
// Write back the cleaned file if we removed anything // Write back the cleaned file if we removed anything
if (autocompleteCleaned > 0) { if (autocompleteCleaned > 0 || pathEntriesRemoved > 0) {
std::ofstream outfile(bashrcPath, std::ios::trunc); std::ofstream outfile(bashrcPath, std::ios::trunc);
for (const auto& l : lines) { for (const auto& l : lines) {
outfile << l << "\n"; 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 " << danglingSymlinksRemoved << " dangling symlinks" << std::endl;
std::cout << " - Removed " << nonSymlinksRemoved << " non-symlinks from ~/.local/bin/getpkg" << std::endl; std::cout << " - Removed " << nonSymlinksRemoved << " non-symlinks from ~/.local/bin/getpkg" << std::endl;
std::cout << " - Cleaned " << autocompleteCleaned << " autocomplete entries" << 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; std::cout << " - Removed " << emptyDirsRemoved << " empty directories" << std::endl;
return 0; return 0;