spoon

set dwm status
git clone git://git.2f30.org/spoon
Log | Files | Refs | LICENSE

commit 208a0a20dc55c2b37db0fcf6326703d96369bc75
parent e3980ef0a7422351304ffe3b87a4fa8192a87c83
Author: Christoph Polcin <labs@polcin.de>
Date:   Wed, 14 Mar 2018 09:06:44 +0100

Add count files plugin

Signed-off-by: Christoph Polcin <labs@polcin.de>

Diffstat:
MMakefile | 4++--
Mconfig.def.h | 1+
Acount.c | 29+++++++++++++++++++++++++++++
Mspoon.c | 1+
Mstub.c | 7+++++++
5 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,8 +1,8 @@ VERSION = 0.5 PREFIX = /usr/local -SRC = spoon.c batt.c wifi.c cpu.c temp.c date.c load.c file.c key.c\ +SRC = spoon.c batt.c wifi.c cpu.c count.c temp.c date.c load.c file.c key.c\ netspeed.c strlcpy.c strlcat.c stub.c mix.c xkblayout.c mpd.c brightness.c -OBJ = spoon.o batt.o wifi.o cpu.o temp.o date.o load.o file.o key.o\ +OBJ = spoon.o batt.o wifi.o cpu.o count.o temp.o date.o load.o file.o key.o\ netspeed.o strlcpy.o strlcat.o stub.o brightness.o BIN = spoon DISTFILES = $(SRC) types.h util.h config.def.h Makefile LICENSE configure diff --git a/config.def.h b/config.def.h @@ -4,6 +4,7 @@ int delay = 1; struct ent ents[] = { /* reorder/remove these as you see fit */ { .fmt = "[%s] ", .read = mpdread, .arg = &(struct mpdarg){ .host = NULL, .port = 0 } }, + { .fmt = "[%s] ", .read = countread, .arg = (char []){"/home/USER/Maildir/INBOX/new"} }, { .fmt = "[%s] ", .read = mixread, .arg = NULL }, { .fmt = "[%s] ", .read = loadread, .arg = NULL }, { .fmt = "[%s] ", .read = cpuread, .arg = NULL }, diff --git a/count.c b/count.c @@ -0,0 +1,29 @@ +#include <dirent.h> +#include <err.h> +#include <stdio.h> +#include <string.h> + +int +countread(void *arg, char *buf, size_t len) +{ + char *path = arg; + unsigned long count = 0; + struct dirent *e; + DIR *d; + + if ((d = opendir(path)) == NULL) { + warn("open %s", path); + return -1; + } + + while ((e = readdir(d)) != NULL) { + if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) + continue; + ++count; + } + closedir(d); + + snprintf(buf, len, "%lu", count); + + return 0; +} diff --git a/spoon.c b/spoon.c @@ -22,6 +22,7 @@ int fileread(void *, char *, size_t); int keyread(void *, char *, size_t); int netspeedread(void *, char *, size_t); int brightnessread(void *, char *, size_t); +int countread(void *, char *, size_t); struct ent { char *fmt; diff --git a/stub.c b/stub.c @@ -76,3 +76,10 @@ brightnessread(void *arg, char *buf, size_t len) { return -1; } + +#pragma weak countread +int +countread(void *arg, char *buf, size_t len) +{ + return -1; +}