commit 19369f8e00efa6fc74132bb37ae3108b9798afa2
parent 55f3661ae465752db40f57946cd0d5e35ddeec49
Author: sam-barr <samfbarr@outlook.com>
Date: Mon, 27 Apr 2020 15:00:00 -0500
Allow for support for other package managers
Diffstat:
3 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/config.h b/config.h
@@ -3,25 +3,25 @@
#define CONFIG \
{ \
- /* name function cached */\
- { "", get_title, false }, \
- { "", get_bar, false }, \
- { "OS: ", get_os, true }, \
- { "Host: ", get_host, true }, \
- { "Kernel: ", get_kernel, true }, \
- { "Uptime: ", get_uptime, false }, \
+ /* name function cached */\
+ { "", get_title, false }, \
+ { "", get_bar, false }, \
+ { "OS: ", get_os, true }, \
+ { "Host: ", get_host, true }, \
+ { "Kernel: ", get_kernel, true }, \
+ { "Uptime: ", get_uptime, false }, \
SPACER \
- { "Packages: ", get_packages, false }, \
- { "Shell: ", get_shell, false }, \
- { "Resolution: ", get_resolution, false }, \
- { "Terminal: ", get_terminal, false }, \
+ { "Packages: ", get_packages_pacman, false }, \
+ { "Shell: ", get_shell, false }, \
+ { "Resolution: ", get_resolution, false }, \
+ { "Terminal: ", get_terminal, false }, \
SPACER \
- { "CPU: ", get_cpu, true }, \
- { "GPU: ", get_gpu1, true }, \
- { "Memory: ", get_memory, false }, \
+ { "CPU: ", get_cpu, true }, \
+ { "GPU: ", get_gpu1, true }, \
+ { "Memory: ", get_memory, false }, \
SPACER \
- { "", get_colors1, false }, \
- { "", get_colors2, false }, \
+ { "", get_colors1, false }, \
+ { "", get_colors2, false }, \
}
#define CPU_REMOVE \
diff --git a/paleofetch.c b/paleofetch.c
@@ -199,34 +199,35 @@ static char *get_uptime() {
return uptime;
}
-// full disclosure: I don't know if this is a good idea
-static char *get_packages() {
+static char *get_packages(const char* dirname, const char* pacname, int num_extraneous) {
int num_packages = 0;
DIR * dirp;
struct dirent *entry;
- dirp = opendir("/var/lib/pacman/local");
+ dirp = opendir(dirname);
if(dirp == NULL) {
status = -1;
- halt_and_catch_fire("Do you not have pacman installed? How did you find this?\n"
- "Please email samfbarr@outlook.com with the details of how you got here.\n"
- "This information will be very useful for my upcoming demographics survey.");
+ halt_and_catch_fire("You may not have %s installed", dirname);
}
while((entry = readdir(dirp)) != NULL) {
if(entry->d_type == DT_DIR) num_packages++;
}
- num_packages -= 2; // accounting for . and ..
+ num_packages -= (2 + num_extraneous); // accounting for . and ..
status = closedir(dirp);
char *packages = malloc(BUF_SIZE);
- snprintf(packages, BUF_SIZE, "%d (pacman)", num_packages);
+ snprintf(packages, BUF_SIZE, "%d (%s)", num_packages, pacname);
return packages;
}
+static char *get_packages_pacman() {
+ return get_packages("/var/lib/pacman/local", "pacman", 0);
+}
+
static char *get_shell() {
char *shell = malloc(BUF_SIZE);
char *shell_path = getenv("SHELL");
diff --git a/paleofetch.h b/paleofetch.h
@@ -7,7 +7,7 @@ static char *get_title(),
*get_kernel(),
*get_host(),
*get_uptime(),
- *get_packages(),
+ *get_packages_pacman(),
*get_shell(),
*get_resolution(),
*get_terminal(),