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