update: big update added the executable option!

This commit is contained in:
Kaley, Fischer 2024-01-14 13:04:19 +01:00
parent ac0645956f
commit 6d01349719

View file

@ -11,12 +11,11 @@
using namespace std;
using namespace cpptoml;
using namespace filesystem;
const string USAGE = R"#(usage: RapidMenu [flags] [<command> [args]]
LISTING COMMANDS:
-c: To specify which config to use.
-b: Make a binary out of a config.
-b: Make a executable out of a config.
)#";
const string invalidvalue = R"#(Invalid value in config: )#";
@ -50,6 +49,10 @@ void from_toml(const table& t, Action& a) {
int main(int argc, char* argv[]) {
const char* configFile = nullptr;
const char* configFile2 = nullptr;
const char* userHome = getenv("HOME");
string rapidMenuPath = string(userHome) + "/.config/RapidMenu";
if (argc > 1 && strcmp(argv[1], "-c") == 0) {
if (argc < 3 || argv[2][0] == '-') {
@ -58,24 +61,11 @@ int main(int argc, char* argv[]) {
}
configFile = argv[2];
} else if (argc > 1 && strcmp(argv[1], "-d") == 0) {
cerr << USAGE.c_str() << endl;
return 0;
}else{
cerr << USAGE.c_str() << endl;
return 0;
}
if (configFile) {
cerr << USAGE.c_str() << endl;
return 0;
}
const char* userHome = getenv("HOME");
string rapidMenuPath = string(userHome) + "/.config/RapidMenu";
if (exists(rapidMenuPath) && is_directory(rapidMenuPath)) {
if (filesystem::exists(rapidMenuPath) && filesystem::is_directory(rapidMenuPath)) {
} else {
system("mkdir -p /home/$USER/.config/RapidMenu");
cerr << "Setting up config." << endl;
@ -143,5 +133,38 @@ int main(int argc, char* argv[]) {
return 1;
}
} else if (argc > 1 && strcmp(argv[1], "-b") == 0) {
if (argc < 3 || argv[2][0] == '-') {
cerr << USAGE.c_str() << endl;
return 1;
}
const char* bconfig = nullptr;
const char* bexe = nullptr;
string bexeout;
bconfig = argv[2];
cout << "What do you want to call your executable?: ";
cin >> bexeout;
if (bexeout.empty()) {
cerr << "Error: Executable name cannot be empty." << endl;
return 1;
}
const char* bexe = bexeout.c_str();
system(("touch /home/$USER/.local/bin/" + string(bexe)).c_str());
system(("chmod +x /home/$USER/.local/bin/" + string(bexe)).c_str());
system(("echo '#!/usr/bin/env bash' > /home/$USER/.local/bin/" + string(bexe)).c_str());
system(("echo 'RapidMenu -c " + string(bconfig) + "' >> /home/$USER/.local/bin/" + string(bexe)).c_str());
}else{
cerr << USAGE.c_str() << endl;
return 0;
}
return 0;
}