From f24f6756b120022ebb6bfadb900f41839789b16e Mon Sep 17 00:00:00 2001 From: DarN Date: Sat, 15 May 2021 13:21:59 +0200 Subject: [PATCH] Added branch detection for Manjaro --- src/modules/packages.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/modules/packages.c b/src/modules/packages.c index 5eb0050b0..f5ff8da9e 100644 --- a/src/modules/packages.c +++ b/src/modules/packages.c @@ -53,6 +53,37 @@ static uint32_t getNumStrings(const char* filename, const char* needle) return count; } +static void getActiveBranch() +{ + FILE* file = fopen("/etc/pacman-mirrors.conf", "r"); + if(file == NULL) + return; // No file or not Manjaro/based + + char* line = NULL; + size_t len = 0, strip; + uint_fast8_t match = 0; + + while (getline(&line, &len, file) != EOF) + { + if((strip = strspn(line, "\t ") > 0)) { + if(strip != len) + memmove(line, line + strip, len + 1 - strip); + } + if((match = sscanf(line, "Branch = %s", line)) > 0) + break; + } + + fclose(file); + + if(match > 0) + printf("[%s]", line); + else + printf("[stable]"); // defaults to stable + + if(line != NULL) + free(line); +} + void ffPrintPackages(FFinstance* instance) { uint32_t pacman = getNumElements("/var/lib/pacman/local", DT_DIR); @@ -77,6 +108,8 @@ void ffPrintPackages(FFinstance* instance) if(name > 0) \ { \ printf("%u ("#name")", name); \ + if(name == pacman) \ + getActiveBranch(); \ if((all = all - name) > 0) \ printf(", "); \ };