:-'Generic Commit'
This commit is contained in:
parent
430d6e0a6f
commit
f5e39a64eb
@ -202,7 +202,10 @@ function build_arch() {
|
|||||||
cd "${ARCH_BUILD_DIR}" || exit 1
|
cd "${ARCH_BUILD_DIR}" || exit 1
|
||||||
ninja -j"${JOBS}"
|
ninja -j"${JOBS}"
|
||||||
|
|
||||||
|
if [ "$RELEASE" -eq 1 ]; then
|
||||||
upx "${ARCH_BUILD_DIR}/${EXECUTABLE_NAME}"
|
upx "${ARCH_BUILD_DIR}/${EXECUTABLE_NAME}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -d "${OUTPUT_DIR}" ]; then
|
if [ ! -d "${OUTPUT_DIR}" ]; then
|
||||||
mkdir -p "${OUTPUT_DIR}"
|
mkdir -p "${OUTPUT_DIR}"
|
||||||
fi
|
fi
|
||||||
|
@ -4,92 +4,133 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
std::string removeWhitespace(const std::string& s) {
|
namespace dropshelltool
|
||||||
|
{
|
||||||
|
|
||||||
|
static const std::filesystem::path DROPSHELL_RC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc_dropshell_tool";
|
||||||
|
static const std::filesystem::path BASHRC_PATH = std::filesystem::path(std::getenv("HOME")) / ".bashrc";
|
||||||
|
|
||||||
|
std::string removeWhitespace(const std::string &s)
|
||||||
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
for (char c : s) {
|
for (char c : s)
|
||||||
if (!isspace(static_cast<unsigned char>(c))) out += c;
|
{
|
||||||
|
if (!isspace(static_cast<unsigned char>(c)))
|
||||||
|
out += c;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr const char* BLOCK_START = "#---DROPSHELL-TOOL-START---";
|
static constexpr const char *BLOCK_START = "#---DROPSHELL-TOOL-START---";
|
||||||
static constexpr const char* BLOCK_END = "#---DROPSHELL-TOOL-END---";
|
static constexpr const char *BLOCK_END = "#---DROPSHELL-TOOL-END---";
|
||||||
|
|
||||||
BashrcEditor::BashrcEditor(const std::string& bashrcPath) : bashrcPath(bashrcPath) {}
|
BashrcEditor::BashrcEditor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
bool BashrcEditor::hasSourceLine(const std::string& scriptPath) const {
|
bool BashrcEditor::hasSourceLine() const
|
||||||
std::ifstream infile(bashrcPath);
|
{
|
||||||
if (!infile) return false;
|
std::ifstream infile(BASHRC_PATH);
|
||||||
|
if (!infile)
|
||||||
|
return false;
|
||||||
std::string line;
|
std::string line;
|
||||||
bool inBlock = false;
|
bool inBlock = false;
|
||||||
const std::string blockStart = removeWhitespace(BLOCK_START);
|
const std::string blockStart = removeWhitespace(BLOCK_START);
|
||||||
const std::string blockEnd = removeWhitespace(BLOCK_END);
|
const std::string blockEnd = removeWhitespace(BLOCK_END);
|
||||||
const std::string target = "source \"" + scriptPath + "\"";
|
const std::string target = "source \"" + DROPSHELL_RC_PATH.string() + "\"";
|
||||||
while (std::getline(infile, line)) {
|
while (std::getline(infile, line))
|
||||||
|
{
|
||||||
std::string trimmed = removeWhitespace(line);
|
std::string trimmed = removeWhitespace(line);
|
||||||
if (trimmed == blockStart) {
|
if (trimmed == blockStart)
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void BashrcEditor::addSourceLine(const std::string& scriptPath) {
|
void BashrcEditor::addSourceLine()
|
||||||
std::ifstream infile(bashrcPath);
|
{
|
||||||
|
std::ifstream infile(BASHRC_PATH);
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
std::string line;
|
std::string line;
|
||||||
bool inBlock = false;
|
bool inBlock = false;
|
||||||
const std::string blockStart = removeWhitespace(BLOCK_START);
|
const std::string blockStart = removeWhitespace(BLOCK_START);
|
||||||
const std::string blockEnd = removeWhitespace(BLOCK_END);
|
const std::string blockEnd = removeWhitespace(BLOCK_END);
|
||||||
while (std::getline(infile, line)) {
|
while (std::getline(infile, line))
|
||||||
|
{
|
||||||
std::string trimmed = removeWhitespace(line);
|
std::string trimmed = removeWhitespace(line);
|
||||||
if (trimmed == blockStart) {
|
if (trimmed == blockStart)
|
||||||
|
{
|
||||||
inBlock = true;
|
inBlock = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (trimmed == blockEnd) {
|
if (trimmed == blockEnd)
|
||||||
|
{
|
||||||
inBlock = false;
|
inBlock = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!inBlock) {
|
if (!inBlock)
|
||||||
|
{
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
infile.close();
|
infile.close();
|
||||||
lines.push_back(BLOCK_START);
|
lines.push_back(BLOCK_START);
|
||||||
lines.push_back("source \"" + scriptPath + "\"");
|
lines.push_back("source \"" + DROPSHELL_RC_PATH.string() + "\"");
|
||||||
lines.push_back(BLOCK_END);
|
lines.push_back(BLOCK_END);
|
||||||
std::ofstream outfile(bashrcPath, std::ios::trunc);
|
std::ofstream outfile(BASHRC_PATH, std::ios::trunc);
|
||||||
for (const auto& l : lines) {
|
for (const auto &l : lines)
|
||||||
|
{
|
||||||
outfile << l << "\n";
|
outfile << l << "\n";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void BashrcEditor::removeSourceLine(const std::string& /*scriptPath*/) {
|
outfile.close();
|
||||||
std::ifstream infile(bashrcPath);
|
|
||||||
|
if (!std::filesystem::exists(DROPSHELL_RC_PATH))
|
||||||
|
{
|
||||||
|
std::filesystem::create_directories(DROPSHELL_RC_PATH.parent_path());
|
||||||
|
std::ofstream outfile(DROPSHELL_RC_PATH, std::ios::trunc);
|
||||||
|
outfile << "echo 'Dropshell tools configured'" << std::endl;
|
||||||
|
outfile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BashrcEditor::removeSourceLine()
|
||||||
|
{
|
||||||
|
std::ifstream infile(BASHRC_PATH);
|
||||||
std::vector<std::string> lines;
|
std::vector<std::string> lines;
|
||||||
std::string line;
|
std::string line;
|
||||||
bool inBlock = false;
|
bool inBlock = false;
|
||||||
const std::string blockStart = removeWhitespace(BLOCK_START);
|
const std::string blockStart = removeWhitespace(BLOCK_START);
|
||||||
const std::string blockEnd = removeWhitespace(BLOCK_END);
|
const std::string blockEnd = removeWhitespace(BLOCK_END);
|
||||||
while (std::getline(infile, line)) {
|
while (std::getline(infile, line))
|
||||||
|
{
|
||||||
std::string trimmed = removeWhitespace(line);
|
std::string trimmed = removeWhitespace(line);
|
||||||
if (trimmed == blockStart) {
|
if (trimmed == blockStart)
|
||||||
|
{
|
||||||
inBlock = true;
|
inBlock = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (trimmed == blockEnd) {
|
if (trimmed == blockEnd)
|
||||||
|
{
|
||||||
inBlock = false;
|
inBlock = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!inBlock) {
|
if (!inBlock)
|
||||||
|
{
|
||||||
lines.push_back(line);
|
lines.push_back(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
infile.close();
|
infile.close();
|
||||||
std::ofstream outfile(bashrcPath, std::ios::trunc);
|
std::ofstream outfile(BASHRC_PATH, std::ios::trunc);
|
||||||
for (const auto& l : lines) {
|
for (const auto &l : lines)
|
||||||
|
{
|
||||||
outfile << l << "\n";
|
outfile << l << "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,15 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
namespace dropshelltool {
|
||||||
|
|
||||||
class BashrcEditor {
|
class BashrcEditor {
|
||||||
public:
|
public:
|
||||||
BashrcEditor(const std::string& bashrcPath);
|
BashrcEditor();
|
||||||
// Checks if the unique block with the source line exists
|
// Checks if the unique block with the source line exists
|
||||||
bool hasSourceLine(const std::string& scriptPath) const;
|
bool hasSourceLine() const;
|
||||||
// Adds or updates the unique block with the given scriptPath
|
// Adds or updates the unique block with the given scriptPath
|
||||||
void addSourceLine(const std::string& scriptPath);
|
void addSourceLine();
|
||||||
// Removes the unique block
|
// Removes the unique block
|
||||||
void removeSourceLine(const std::string& scriptPath);
|
void removeSourceLine();
|
||||||
private:
|
|
||||||
std::string bashrcPath;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace dropshelltool
|
@ -69,13 +69,22 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
std::string command = argv[1];
|
std::string command = argv[1];
|
||||||
if (command == "install") {
|
if (command == "install") {
|
||||||
|
dropshelltool::BashrcEditor bashrcEditor;
|
||||||
|
bashrcEditor.addSourceLine();
|
||||||
// TODO: Implement install logic using utility classes
|
// TODO: Implement install logic using utility classes
|
||||||
} else if (command == "publish") {
|
} else if (command == "publish") {
|
||||||
// TODO: Implement publish logic
|
// TODO: Implement publish logic
|
||||||
} else if (command == "update") {
|
} else if (command == "update") {
|
||||||
// TODO: Implement update logic
|
// TODO: Implement update logic
|
||||||
} else if (command == "autocomplete") {
|
} else if (command == "autocomplete") {
|
||||||
// TODO: Implement autocomplete logic
|
std::vector<std::string> args(argv + 2, argv + argc);
|
||||||
|
if (args.empty()) std::cout << R"(install
|
||||||
|
publish
|
||||||
|
update
|
||||||
|
version
|
||||||
|
create
|
||||||
|
help
|
||||||
|
)";
|
||||||
} else if (command == "version") {
|
} else if (command == "version") {
|
||||||
std::cout << dropshell::VERSION << std::endl;
|
std::cout << dropshell::VERSION << std::endl;
|
||||||
} else if (command == "create") {
|
} else if (command == "create") {
|
||||||
@ -86,7 +95,6 @@ int main(int argc, char* argv[]) {
|
|||||||
std::cout << " install <tool_name>" << std::endl;
|
std::cout << " install <tool_name>" << std::endl;
|
||||||
std::cout << " publish <tool_name:ARCH> <folder>" << std::endl;
|
std::cout << " publish <tool_name:ARCH> <folder>" << std::endl;
|
||||||
std::cout << " update <tool_name>" << std::endl;
|
std::cout << " update <tool_name>" << std::endl;
|
||||||
std::cout << " autocomplete <args>" << std::endl;
|
|
||||||
std::cout << " version" << std::endl;
|
std::cout << " version" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Unknown command: " << command << std::endl;
|
std::cout << "Unknown command: " << command << std::endl;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user