Compare commits

..
3 Commits
7 changed files with 163 additions and 77 deletions
+6 -4
View File
@@ -1,4 +1,4 @@
.TH MANAFILES 1 "2022-01-29" "manafiles 0.5" "User Commands" .TH MANAFILES 1 "2025-02-02" "manafiles 0.6" "User Commands"
.SH NAME .SH NAME
manafiles \- config file and package tracking utility manafiles \- config file and package tracking utility
@@ -31,7 +31,7 @@ See File Options below.
.TP .TP
.BR \-P ", " \-\-package .BR \-P ", " \-\-package
Operate on packages. \ Operate on packages. \
This operation allows you to track installed packages and reinstall them. \ This operation allows tracking installed packages and reinstalling them. \
In the first case, if no package names are provided in the command line, all packages will be selected. \ In the first case, if no package names are provided in the command line, all packages will be selected. \
See Package Options below. See Package Options below.
@@ -67,8 +67,10 @@ Install all AUR packages of the stored list.
Install all official packages of the stored list. Install all official packages of the stored list.
.TP .TP
.BR \-s ", " \-\-store .BR \-s ", " \-\-search
Stores a list of all installed packages on the system. Search each locally-installed package for names via a partial match. \
When including multiple search terms, all packages with names matching any of those terms are returned. \
If the \fB-s\fR option is ommited, packages names are filtered via a full match.
.SH EXAMPLES .SH EXAMPLES
Usage examples: Usage examples:
+14 -3
View File
@@ -405,16 +405,27 @@ void Dotfile::selectivelyCommentOrUncomment(const std::string& path)
size_t lineLength = line.size(); size_t lineLength = line.size();
size_t commentStart = line.find(commentCharacter, indentation); size_t commentStart = line.find(commentCharacter, indentation);
size_t commentEnd = line.find(commentTerminationCharacter, commentStart); size_t commentEnd = line.rfind(commentTerminationCharacter);
bool hasComment = commentStart != std::string::npos && commentEnd != std::string::npos; bool hasComment = commentStart != std::string::npos && (commentTerminationCharacter.empty() || commentEnd != std::string::npos);
// Lines that have a comment at the *end* of the line aren't considered commented lines
if (hasComment && line.find_first_not_of(" \t") < commentStart) {
hasComment = false;
}
// Uncomment line
if (hasComment && !addComment) { if (hasComment && !addComment) {
size_t contentStart = line.find_first_not_of(" \t", commentStart + commentCharacter.size()); size_t contentStart = line.find_first_not_of(" \t", commentStart + commentCharacter.size());
size_t contentLength = commentEnd - contentStart; size_t contentLength = commentEnd - contentStart;
// Trim trailing whitespace
std::string content = line.substr(contentStart, contentLength);
content = content.substr(0, content.find_last_not_of(" \t") + 1);
line = line.substr(0, indentation) line = line.substr(0, indentation)
+ line.substr(contentStart, contentLength); + content;
} }
// Comment line
else if (!hasComment && addComment) { else if (!hasComment && addComment) {
size_t contentStart = line.find_first_not_of(" \t"); size_t contentStart = line.find_first_not_of(" \t");
size_t contentLength = line.size() - contentStart; size_t contentLength = line.size() - contentStart;
+14 -8
View File
@@ -72,18 +72,24 @@ void Machine::fetchSession()
int8_t likelyWayland = 0; int8_t likelyWayland = 0;
// Detect via environment variable // Detect via environment variable
std::string env; const char* env;
env = std::string(std::getenv("XDG_SESSION_TYPE")); env = std::getenv("XDG_SESSION_TYPE");
if (env == "wayland") { if (env != nullptr) {
auto session = std::string(env);
if (session == "wayland") {
likelyWayland++; likelyWayland++;
} }
else if (env == "x11") { else if (session == "x11") {
likelyWayland--; likelyWayland--;
} }
env = std::string(std::getenv("WAYLAND_DISPLAY")); }
if (env.find("wayland-", 0) == 0) { env = std::getenv("WAYLAND_DISPLAY");
if (env != nullptr) {
auto display = std::string(env);
if (display.find("wayland-", 0) == 0) {
likelyWayland++; likelyWayland++;
} }
}
// Detect via Wayland socket // Detect via Wayland socket
auto socket = std::filesystem::path("/run/user") / std::to_string(uid()); auto socket = std::filesystem::path("/run/user") / std::to_string(uid());
@@ -117,12 +123,12 @@ void Machine::fetchSession()
std::string command; std::string command;
std::getline(stream, command); std::getline(stream, command);
if (command == "Xwayland" || command == "hyprland" || command == "sway") { if (command == "Xwayland" || command == "sway" || command == "hyprland") {
likelyWayland++; likelyWayland++;
break; break;
} }
if (command == "Xorg" || command == "xinit" || command == "bspwm") { if (command == "Xorg" || command == "xinit" || command == "i3" || command == "bspwm") {
likelyWayland--; likelyWayland--;
break; break;
} }
+14 -16
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Riyyi * Copyright (C) 2021-2022,2025 Riyyi
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
@@ -8,11 +8,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "ruc/argparser.h"
#include "ruc/timer.h"
#include "config.h" #include "config.h"
#include "dotfile.h" #include "dotfile.h"
#include "package.h" #include "package.h"
#include "ruc/argparser.h"
#include "ruc/timer.h"
int main(int argc, const char* argv[]) int main(int argc, const char* argv[])
{ {
@@ -23,7 +24,7 @@ int main(int argc, const char* argv[])
bool addOrAur = false; bool addOrAur = false;
bool install = false; bool install = false;
bool pull = false; bool pull = false;
bool pushOrStore = false; bool pushOrSearch = false;
bool verbose = false; bool verbose = false;
std::vector<std::string> targets {}; std::vector<std::string> targets {};
@@ -36,7 +37,7 @@ int main(int argc, const char* argv[])
argParser.addOption(addOrAur, 'a', "add", nullptr, nullptr); argParser.addOption(addOrAur, 'a', "add", nullptr, nullptr);
argParser.addOption(install, 'i', "install", nullptr, nullptr); argParser.addOption(install, 'i', "install", nullptr, nullptr);
argParser.addOption(pull, 'l', "pull", nullptr, nullptr); argParser.addOption(pull, 'l', "pull", nullptr, nullptr);
argParser.addOption(pushOrStore, 's', "push", nullptr, nullptr); argParser.addOption(pushOrSearch, 's', "push", nullptr, nullptr);
argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr); argParser.addOption(verbose, 'v', "verbose", nullptr, nullptr);
argParser.addArgument(targets, "targets", nullptr, nullptr, ruc::ArgParser::Required::No); argParser.addArgument(targets, "targets", nullptr, nullptr, ruc::ArgParser::Required::No);
@@ -60,32 +61,29 @@ int main(int argc, const char* argv[])
if (pull) { if (pull) {
Dotfile::the().pull(targets); Dotfile::the().pull(targets);
} }
if (pushOrStore) { if (pushOrSearch) {
Dotfile::the().push(targets); Dotfile::the().push(targets);
} }
if (!addOrAur && !pull && !pushOrStore) { if (!addOrAur && !pull && !pushOrSearch) {
Dotfile::the().list(targets); Dotfile::the().list(targets);
} }
} }
else if (packageOperation) { else if (packageOperation) {
if (addOrAur) { if (addOrAur) {
Package::the().aurInstall(); Package::the().aurInstall(targets);
} }
if (install) { if (install) {
Package::the().install(); Package::the().install(targets);
} }
if (pushOrStore) { if (!addOrAur && !install) {
Package::the().store(); Package::the().list(targets, pushOrSearch);
}
if (!addOrAur && !install && !pushOrStore) {
Package::the().list(targets);
} }
} }
else if (helpOperation) { else if (helpOperation) {
// TODO open manpage // TODO: open manpage
} }
else { else {
// TODO open manpage // TODO: open manpage
} }
#ifndef NDEBUG #ifndef NDEBUG
+25 -29
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Riyyi * Copyright (C) 2021-2022,2025 Riyyi
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
@@ -14,12 +14,12 @@
#include <string> // getline #include <string> // getline
#include <vector> #include <vector>
#include "machine.h"
#include "package.h"
#include "ruc/file.h"
#include "ruc/shell.h" #include "ruc/shell.h"
#include "ruc/system.h" #include "ruc/system.h"
#include "machine.h"
#include "package.h"
Package::Package(s) Package::Package(s)
{ {
} }
@@ -30,17 +30,27 @@ Package::~Package()
// ----------------------------------------- // -----------------------------------------
void Package::aurInstall() void Package::aurInstall(const std::vector<std::string>& targets)
{ {
installOrAurInstall(InstallType::AurInstall); if (targets.size() > 1) {
fprintf(stderr, "\033[31;1mPackage:\033[0m only 1 file can be read packages from at a time\n");
return;
} }
void Package::install() installOrAurInstall(InstallType::AurInstall, targets.size() != 0 ? targets.front() : PACKAGE_FILE);
{
installOrAurInstall(InstallType::Install);
} }
void Package::list(const std::vector<std::string>& targets) void Package::install(const std::vector<std::string>& targets)
{
if (targets.size() > 1) {
fprintf(stderr, "\033[31;1mPackage:\033[0m only 1 file can be read packages from at a time\n");
return;
}
installOrAurInstall(InstallType::Install, targets.size() != 0 ? targets.front() : PACKAGE_FILE);
}
void Package::list(const std::vector<std::string>& targets, bool partialMatch)
{ {
auto packagesOrEmpty = getPackageList(); auto packagesOrEmpty = getPackageList();
@@ -62,7 +72,7 @@ void Package::list(const std::vector<std::string>& targets)
std::string line; std::string line;
while (std::getline(stream, line)) { while (std::getline(stream, line)) {
for (const auto& target : targets) { for (const auto& target : targets) {
if (line.find(target) != std::string::npos) { if (line == target || (partialMatch && line.find(target) != std::string::npos)) {
packages.append(line + '\n'); packages.append(line + '\n');
break; break;
} }
@@ -72,20 +82,6 @@ void Package::list(const std::vector<std::string>& targets)
printf("%s", packages.c_str()); printf("%s", packages.c_str());
} }
void Package::store()
{
auto packagesOrEmpty = getPackageList();
if (!packagesOrEmpty.has_value()) {
return;
}
auto packageFile = ruc::File::create("./packages");
packageFile.clear();
packageFile.append(packagesOrEmpty.value());
packageFile.flush();
}
// ----------------------------------------- // -----------------------------------------
std::optional<std::string> Package::fetchAurHelper() std::optional<std::string> Package::fetchAurHelper()
@@ -105,7 +101,7 @@ std::optional<std::string> Package::fetchAurHelper()
return {}; return {};
} }
void Package::installOrAurInstall(InstallType type) void Package::installOrAurInstall(InstallType type, const std::string& file)
{ {
distroDetect(); distroDetect();
distroDependencies(); distroDependencies();
@@ -129,12 +125,12 @@ void Package::installOrAurInstall(InstallType type)
ruc::System $; ruc::System $;
if (m_distro == Distro::Arch) { if (m_distro == Distro::Arch) {
// Grab everything off enabled official repositories that is in the list // Grab everything off enabled official repositories that is in the list
auto repoList = $("pacman -Ssq") | $("grep -xf ./packages"); auto repoList = $("pacman -Ssq") | $("grep -xf " + file);
if (type == InstallType::AurInstall) { if (type == InstallType::AurInstall) {
// Determine which packages in the list are from the AUR // Determine which packages in the list are from the AUR
// NOTE: ruc::System does not support commands with newlines // NOTE: ruc::System does not support commands with newlines
auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' ./packages"); auto aurList = ruc::Shell()("grep -vx '" + repoList.output() + "' " + file);
command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output(); command = aurHelper.value() + " -Sy --devel --needed --noconfirm " + aurList.output();
} }
else { else {
@@ -143,7 +139,7 @@ void Package::installOrAurInstall(InstallType type)
} }
else if (m_distro == Distro::Debian) { else if (m_distro == Distro::Debian) {
// Grab everything off enabled official repositories that is in the list // Grab everything off enabled official repositories that is in the list
auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf ./packages"); auto repoList = $("apt-cache search .").cut(1, ' ') | $("grep -xf " + file);
command = "apt install " + repoList.output(); command = "apt install " + repoList.output();
} }
+7 -6
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2021-2022 Riyyi * Copyright (C) 2021-2022,2025 Riyyi
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
@@ -13,6 +13,8 @@
#include "ruc/singleton.h" #include "ruc/singleton.h"
#define PACKAGE_FILE "./packages"
class Package : public ruc::Singleton<Package> { class Package : public ruc::Singleton<Package> {
public: public:
Package(s); Package(s);
@@ -29,14 +31,13 @@ public:
AurInstall, AurInstall,
}; };
void aurInstall(); void aurInstall(const std::vector<std::string>& targets = {});
void install(); void install(const std::vector<std::string>& targets = {});
void list(const std::vector<std::string>& targets = {}); void list(const std::vector<std::string>& targets = {}, bool partialMatch = false);
void store();
private: private:
std::optional<std::string> fetchAurHelper(); std::optional<std::string> fetchAurHelper();
void installOrAurInstall(InstallType type); void installOrAurInstall(InstallType type, const std::string& file);
bool findDependency(const std::string& search); bool findDependency(const std::string& search);
bool distroDetect(); bool distroDetect();
+77 -5
View File
@@ -1,11 +1,10 @@
/* /*
* Copyright (C) 2022 Riyyi * Copyright (C) 2022,2025 Riyyi
* *
* SPDX-License-Identifier: MIT * SPDX-License-Identifier: MIT
*/ */
#include <cstddef> // size_t #include <cstddef> // size_t
#include <cstdint> // uint32_t
#include <cstdio> // stderr #include <cstdio> // stderr
#include <filesystem> // path #include <filesystem> // path
#include <string> #include <string>
@@ -13,12 +12,12 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "ruc/file.h"
#include "config.h" #include "config.h"
#include "dotfile.h" #include "dotfile.h"
#include "machine.h" #include "machine.h"
#include "macro.h" #include "macro.h"
#include "ruc/file.h"
#include "ruc/system.h"
#include "testcase.h" #include "testcase.h"
#include "testsuite.h" #include "testsuite.h"
@@ -503,7 +502,7 @@ TEST_CASE(PushDotfilesWithIgnorePattern)
TEST_CASE(PushDotfilesSelectivelyComment) TEST_CASE(PushDotfilesSelectivelyComment)
{ {
std::vector<std::string> fileNames; std::vector<std::string> fileNames;
for (size_t i = 0; i < 36; ++i) { for (size_t i = 0; i < 44; ++i) {
fileNames.push_back("__test-file-" + std::to_string(i + 1)); fileNames.push_back("__test-file-" + std::to_string(i + 1));
} }
@@ -678,6 +677,43 @@ test data /**/ comment
/* test data /**/ uncomment */ /* test data /**/ uncomment */
/* <<< */ /* <<< */
)", )",
// Comment <!---->
"<!-- >>> distro=" + placeholder + " hostname=" + hostname + " user=" + username + " -->" + R"(
test data <!----> comment
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + placeholder + " user=" + username + " -->" + R"(
test data <!----> comment
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + placeholder + " -->" + R"(
test data <!----> comment
<!-- <<< -->
)",
" <!-- >>> distro=" + placeholder + " hostname=" + hostname + " user=" + username + " -->" + R"(
test data <!----> comment
<!-- <<< -->
)",
// Uncomment <!---->
"<!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
<!-- test data <!----> uncomment -->
<!-- <<< -->
)",
" <!-- >>> distro="
+ distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
<!-- test data <!----> uncomment -->
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
<!-- test data <!----> uncomment -->
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
<!-- test data <!----> uncomment -->
<!-- <<< -->
)",
}; };
std::vector<std::string> pushedFileContents = { std::vector<std::string> pushedFileContents = {
@@ -846,6 +882,42 @@ test data /**/ uncomment
test data /**/ uncomment test data /**/ uncomment
/* <<< */ /* <<< */
)", )",
// Comment <!---->
"<!-- >>> distro=" + placeholder + " hostname=" + hostname + " user=" + username + " -->" + R"(
<!-- test data <!----> comment -->
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + placeholder + " user=" + username + " -->" + R"(
<!-- test data <!----> comment -->
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + placeholder + " -->" + R"(
<!-- test data <!----> comment -->
<!-- <<< -->
)",
" <!-- >>> distro=" + placeholder + " hostname=" + hostname + " user=" + username + " -->" + R"(
<!-- test data <!----> comment -->
<!-- <<< -->
)",
// Uncomment <!---->
"<!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
test data <!----> uncomment
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
test data <!----> uncomment
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
test data <!----> uncomment
<!-- <<< -->
)",
" <!-- >>> distro=" + distro + " hostname=" + hostname + " user=" + username + " -->" + R"(
test data <!----> uncomment
<!-- <<< -->
)",
}; };
createTestDotfiles(fileNames, fileContents); createTestDotfiles(fileNames, fileContents);