add pre_script

This commit is contained in:
lucaspalomodevelop 2023-09-03 13:45:25 +02:00
parent e6c3de3d7d
commit fba623e343
2 changed files with 14 additions and 2 deletions

View File

@ -31,6 +31,7 @@ void input(int argc, char *argv[])
command.addCommandAlias("remove", "r"); command.addCommandAlias("remove", "r");
command.addCommand("show", "[script] - Shows a script", showScript); command.addCommand("show", "[script] - Shows a script", showScript);
command.addCommandAlias("show", "s"); command.addCommandAlias("show", "s");
command.addDefaultCommand(runScript); command.addDefaultCommand(runScript);
command.runCommand(argv[1], argc, argv); command.runCommand(argv[1], argc, argv);
} }
@ -42,6 +43,8 @@ void runScript(int argc, char *argv[])
std::map<int, std::string> dir_options; std::map<int, std::string> dir_options;
std::string dir = home_dir; std::string dir = home_dir;
auto script_settings = settings.value["scripts"][argv[1]];
for (auto search_dir : settings.value["search_dirs"]) for (auto search_dir : settings.value["search_dirs"])
{ {
if (std::filesystem::exists((std::string)search_dir + "/" + argv[1])) if (std::filesystem::exists((std::string)search_dir + "/" + argv[1]))
@ -88,6 +91,16 @@ void runScript(int argc, char *argv[])
} }
std::string script = pre_script + dir + "/" + argv[1] + " " + args; std::string script = pre_script + dir + "/" + argv[1] + " " + args;
std::cout << "executing: " << (dir + "/" + argv[1] + " " + args) << std::endl; std::cout << "executing: " << (dir + "/" + argv[1] + " " + args) << std::endl;
// if (script_settings["sudo"])
// script = "sudo " + script;
// if (script_settings["background"])
// script = script + " &";
if (script_settings["pre_script"].size() > 0)
system(script_settings["pre_script"].get<std::string>().c_str());
system(script.c_str()); system(script.c_str());
return; return;
} }

View File

@ -3,7 +3,6 @@
#ifndef MAIN_H #ifndef MAIN_H
#define MAIN_H #define MAIN_H
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <sys/stat.h> #include <sys/stat.h>