From fba623e3435af10a9829b052f1bdd8d461419fdb Mon Sep 17 00:00:00 2001 From: lucaspalomodevelop Date: Sun, 3 Sep 2023 13:45:25 +0200 Subject: [PATCH] add pre_script --- src/main.cpp | 13 +++++++++++++ src/main.h | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index de2a9b2..e1d5acc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -31,6 +31,7 @@ void input(int argc, char *argv[]) command.addCommandAlias("remove", "r"); command.addCommand("show", "[script] - Shows a script", showScript); command.addCommandAlias("show", "s"); + command.addDefaultCommand(runScript); command.runCommand(argv[1], argc, argv); } @@ -42,6 +43,8 @@ void runScript(int argc, char *argv[]) std::map dir_options; std::string dir = home_dir; + auto script_settings = settings.value["scripts"][argv[1]]; + for (auto search_dir : settings.value["search_dirs"]) { 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::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().c_str()); + system(script.c_str()); return; } diff --git a/src/main.h b/src/main.h index 6a6d974..eba237c 100644 --- a/src/main.h +++ b/src/main.h @@ -3,7 +3,6 @@ #ifndef MAIN_H #define MAIN_H - #include #include #include @@ -17,7 +16,7 @@ Settings settings; // directory for autom scripts std::string home_dir = ""; -Command command; +Command command; // input function for parsing arguments and creating commands and running them void input(int argc, char *argv[]);