This commit is contained in:
Your Name
2025-04-21 16:33:46 +12:00
parent 5861c9c776
commit b49bc0c5de
7 changed files with 73 additions and 3 deletions

View File

@ -3,6 +3,7 @@
#include "config.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <set>
namespace fs = boost::filesystem;
@ -58,4 +59,51 @@ std::vector<std::string> autocomplete_list_services(const std::string& server_na
return services;
}
std::vector<std::string> autocomplete_list_commands() {
std::vector<std::string> commands;
std::set<std::string> unique_commands; // To ensure deduplication
// System templates directory
const std::string system_templates_dir = "/opt/dropshell/templates";
// User templates directory
std::string user_templates_dir;
if (!get_user_directory(user_templates_dir)) {
std::cerr << "Error: User directory not set" << std::endl;
return commands;
}
user_templates_dir += "/usertemplates";
// Helper function to add commands from a directory
auto add_commands_from_dir = [&unique_commands](const std::string& dir_path) {
if (!fs::exists(dir_path)) {
return;
}
// Iterate through all template directories
for (const auto& template_entry : fs::directory_iterator(dir_path)) {
if (!fs::is_directory(template_entry)) {
continue;
}
// Look for shell files in each template directory
for (const auto& file_entry : fs::directory_iterator(template_entry.path())) {
if (fs::is_regular_file(file_entry) &&
file_entry.path().extension() == ".sh" &&
file_entry.path().filename().string()[0] != '_') {
unique_commands.insert(file_entry.path().stem().string());
}
}
}
};
// Add commands from both template locations
add_commands_from_dir(system_templates_dir);
add_commands_from_dir(user_templates_dir);
// Convert set to vector for return
commands.assign(unique_commands.begin(), unique_commands.end());
return commands;
}
} // namespace dropshell