Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
✨ Introduce class Context (#98)
Browse files Browse the repository at this point in the history
* Aggregate delimiter.

* Introduce Context

* Remove unused variable.
  • Loading branch information
youpong authored Feb 12, 2023
1 parent 6f93979 commit f88f534
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/fetch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* @file
*/
#include "fetch.h"
string Context::PACKAGE_DELIM = "; "s;

/**
* @returns gets the username
Expand Down Expand Up @@ -352,60 +353,66 @@ vector<string> getGPU()
string getPackages()
{
auto red = Crayon{}.red();
string pkg = "";
vector<string> pkgs;
if (Path::of("/bin/dpkg"s).isExecutable())
{
auto c = Command::exec("dpkg -l"s);
pkg += to_string(c.getOutputLines()) + red.text(" dpkg; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" dpkg"s));
}
if (Path::of("/bin/snap"s).isExecutable())
{
auto c = Command::exec("snap list"s);
pkg += to_string(c.getOutputLines()) + red.text(" snap; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" snap"s));
}
if (Path::of("/bin/pacman"s).isExecutable())
{
auto c = Command::exec("pacman -Q"s);
pkg += to_string(c.getOutputLines()) + red.text(" pacman; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" pacman"s));
}
if (Path::of("/bin/flatpak"s).isExecutable())
{
auto c = Command::exec("flatpak list"s);
pkg += to_string(c.getOutputLines()) + red.text(" flatpak; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" flatpak"s));
}
if (Path::of("/var/lib/rpm"s).isExecutable())
{
auto c = Command::exec("rpm -qa"s);
pkg += to_string(c.getOutputLines()) + red.text(" rpm; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" rpm"s));
}
if (Path::of("/bin/npm"s).isExecutable())
{
auto c = Command::exec("npm list"s);
pkg += to_string(c.getOutputLines()) + red.text(" npm; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" npm"s));
}
if (Path::of("/bin/emerge"s).isExecutable()) // gentoo
{
pkg += "not supported"s + red.text(" portage; ");
pkgs.push_back("not supported"s + red.text(" portage"s));
}
if (Path::of("/bin/xbps-install"s).isExecutable()) // void linux
{
auto c = Command::exec("flatpak list"s);
pkg += to_string(c.getOutputLines()) + red.text(" xbps; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" xbps"s));
}
if (Path::of("/bin/dnf"s).isExecutable()) // fedora
{
auto c = Command::exec("dnf list installed"s);
pkg += to_string(c.getOutputLines()) + red.text(" dnf; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" dnf"s));
}
if (Path::of("/bin/zypper"s).isExecutable()) // opensuse
{
auto c = Command::exec("zypper se --installed-only"s);
pkg += to_string(c.getOutputLines()) + red.text(" zypper; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" zypper"s));
}
if (Path::of("/home/linuxbrew/.linuxbrew/bin/brew"s).isExecutable())
{
auto c = Command::exec("brew list | { tr '' '\n'; }"s);
pkg += to_string(c.getOutputLines()) + red.text(" brew; ");
pkgs.push_back(to_string(c.getOutputLines()) + red.text(" brew"s));
}

auto pkg = ""s;
for (auto p : pkgs)
{
pkg += p + Context::PACKAGE_DELIM;
}

return pkg;
Expand Down
6 changes: 6 additions & 0 deletions src/fetch.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ class Crayon
}
};

class Context
{
public:
static string PACKAGE_DELIM;
};

enum class Mode
{
NORMAL,
Expand Down

0 comments on commit f88f534

Please sign in to comment.