'Generic Commit'
Some checks failed
Build-Test-Publish / build (push) Failing after 19s

This commit is contained in:
Your Name 2025-06-22 08:55:07 +12:00
parent 88556fbff3
commit 758bcde8a7
2 changed files with 30 additions and 22 deletions

View File

@ -24,8 +24,8 @@ namespace dropshelltool
return out; return out;
} }
static constexpr const char *BLOCK_START = "#---DROPSHELL-TOOL-START---"; static constexpr const char *BLOCK_START = "#---GETPKG-TOOL-START---";
static constexpr const char *BLOCK_END = "#---DROPSHELL-TOOL-END---"; static constexpr const char *BLOCK_END = "#--GETPKG-TOOL-END---";
BashrcEditor::BashrcEditor() BashrcEditor::BashrcEditor()
{ {

View File

@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include <filesystem> #include <filesystem>
#include <algorithm> #include <algorithm>
#include <iostream>
namespace dropshelltool { namespace dropshelltool {
extern const std::filesystem::path DROPSHELL_RC_PATH; extern const std::filesystem::path DROPSHELL_RC_PATH;
@ -72,19 +73,23 @@ void DropshellScriptManager::addAutocomplete(const std::string& toolName) {
std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH); std::ifstream infile(dropshelltool::DROPSHELL_RC_PATH);
std::vector<std::string> lines; std::vector<std::string> lines;
std::string line; std::string line;
std::string funcName = "_" + toolName + "_autocomplete"; std::string funcName = "_" + toolName + "_autocomplete";
std::string blockStart = "# DROPSHELL-AUTOCOMPLETE-START: " + toolName;
std::string blockEnd = "# DROPSHELL-AUTOCOMPLETE-END: " + toolName; std::string blockStart = "# GETPKG-AUTOCOMPLETE-START: " + toolName;
std::string funcDef; std::string blockEnd = "# GETPKG-AUTOCOMPLETE-END: " + toolName;
funcDef += blockStart + "\n";
funcDef += funcName + "() {\n"; std::vector<std::string> funcLines;
funcDef += " local cur=\"${COMP_WORDS[COMP_CWORD]}\"\n"; funcLines.push_back(blockStart);
funcDef += " mapfile -t completions < <(" + toolName + " autocomplete \"${COMP_WORDS[@]:1:${COMP_CWORD}-1}\")\n"; funcLines.push_back(funcName + "() {");
funcDef += " mapfile -t COMPREPLY < <(compgen -W \"${completions[*]}\" -- \"$cur\")\n"; funcLines.push_back(" local cur=\"${COMP_WORDS[COMP_CWORD]}\"");
funcDef += "}\n"; funcLines.push_back(" mapfile -t completions < <(" + toolName + " autocomplete \"${COMP_WORDS[@]:1:${COMP_CWORD}-1}\")");
funcDef += blockEnd + "\n"; funcLines.push_back(" mapfile -t COMPREPLY < <(compgen -W \"${completions[*]}\" -- \"$cur\")");
std::string completeLine = "complete -F " + funcName + " " + toolName + " # dropshell-autocomplete:" + toolName; funcLines.push_back("}");
bool blockFound = false, completeFound = false; funcLines.push_back(blockEnd);
std::string completeLine = "complete -F " + funcName + " " + toolName + " # autocomplete: " + toolName;
bool blockFound = false;
bool inBlock = false; bool inBlock = false;
while (std::getline(infile, line)) { while (std::getline(infile, line)) {
if (!inBlock && trim(line) == blockStart) { if (!inBlock && trim(line) == blockStart) {
@ -95,20 +100,23 @@ void DropshellScriptManager::addAutocomplete(const std::string& toolName) {
if (inBlock) { if (inBlock) {
if (trim(line) == blockEnd) { if (trim(line) == blockEnd) {
inBlock = false; inBlock = false;
lines.push_back(funcDef); // Add new function block // Add all function lines
for (const auto& funcLine : funcLines) {
lines.push_back(funcLine);
}
} }
continue; // Skip all lines in the old block continue; // Skip all lines in the old block
} }
if (line.find("# dropshell-autocomplete:" + toolName) != std::string::npos) { else
completeFound = true;
lines.push_back(completeLine);
} else {
lines.push_back(line); lines.push_back(line);
} }
}
infile.close(); infile.close();
if (!blockFound) lines.push_back(funcDef); if (!blockFound) {
if (!completeFound) lines.push_back(completeLine); // Add all function lines
for (const auto& funcLine : funcLines) {
lines.push_back(funcLine);
}
}
std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc); std::ofstream outfile(dropshelltool::DROPSHELL_RC_PATH, std::ios::trunc);
for (const auto& l : lines) outfile << l << "\n"; for (const auto& l : lines) outfile << l << "\n";
outfile.close(); outfile.close();