From dcc0cddee4457d88528b75bab2d6705ff06770d9 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 16:57:55 +0200 Subject: [PATCH 01/16] simpler usage --- slstatus.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/slstatus.c b/slstatus.c index fa12572..174a17c 100644 --- a/slstatus.c +++ b/slstatus.c @@ -592,10 +592,7 @@ sighandler(const int signo) static void usage(void) { - fprintf(stderr, - "slstatus (c) 2016, drkhsh\n" - "usage: %s [-dho]\n", - argv0); + fprintf(stderr, "usage: %s [-dho]\n", argv0); exit(1); } -- 2.20.1 From 14749b6c878f231a1120fc750d38f0c4383090a1 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 17:03:53 +0200 Subject: [PATCH 02/16] added -v command line option --- slstatus.1 | 3 +++ slstatus.c | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/slstatus.1 b/slstatus.1 index fd32981..adaf052 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -16,6 +16,9 @@ displays usage .TP .B \-o output to console instead of WM_NAME +.TP +.B \-v +display version and copyright details .SH CUSTOMIZATION .B slstatus can be customized by creating a custom config.h and (re)compiling the source diff --git a/slstatus.c b/slstatus.c index 174a17c..8479bf1 100644 --- a/slstatus.c +++ b/slstatus.c @@ -592,7 +592,7 @@ sighandler(const int signo) static void usage(void) { - fprintf(stderr, "usage: %s [-dho]\n", argv0); + fprintf(stderr, "usage: %s [-dhov]\n", argv0); exit(1); } @@ -612,6 +612,9 @@ main(int argc, char *argv[]) case 'o': oflag = 1; break; + case 'v': + printf("%s version %s (c) 2016 slstatus engineers\n", argv0, VERSION); + return 0; default: usage(); } ARGEND -- 2.20.1 From cfa0d9e8feacd6a314ac443716c0c2496b9a1462 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 17:15:50 +0200 Subject: [PATCH 03/16] optimization --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index e29f054..bb6b8e8 100644 --- a/config.mk +++ b/config.mk @@ -11,7 +11,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound # flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE -CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -O2 ${INCS} ${CPPFLAGS} +CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} CC = cc -- 2.20.1 From d1423010d0832e6da3c11bea63e5f5299a21710b Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 17:22:12 +0200 Subject: [PATCH 04/16] config.mk comment about -Wno-unused-functions --- config.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config.mk b/config.mk index bb6b8e8..75463df 100644 --- a/config.mk +++ b/config.mk @@ -1,3 +1,5 @@ +# See LICENSE file for copyright and license details. + VERSION = 2.0 PREFIX = /usr/local @@ -9,11 +11,10 @@ X11LIB = /usr/X11R6/lib INCS = -I. -I/usr/include -I${X11INC} LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound -# flags CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE +# -Wno-unused-function for routines not activated by user CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} CC = cc LD = ld - -- 2.20.1 From 0fe8e5a961a32e56412a06b4a31a6ba543fd2dfb Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 17:26:01 +0200 Subject: [PATCH 05/16] suckless coding style -> added back function prototypes argument variable names --- slstatus.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/slstatus.c b/slstatus.c index 8479bf1..49b14de 100644 --- a/slstatus.c +++ b/slstatus.c @@ -37,34 +37,34 @@ struct arg { const char *args; }; -static char *smprintf(const char *, ...); -static char *battery_perc(const char *); -static char *battery_state(const char *); +static char *smprintf(const char *fmt, ...); +static char *battery_perc(const char *bat); +static char *battery_state(const char *bat); static char *cpu_perc(void); -static char *datetime(const char *); -static char *disk_free(const char *); -static char *disk_perc(const char *); -static char *disk_total(const char *); -static char *disk_used(const char *); +static char *datetime(const char *fmt); +static char *disk_free(const char *mnt); +static char *disk_perc(const char *mnt); +static char *disk_total(const char *mnt); +static char *disk_used(const char *mnt); static char *entropy(void); static char *gid(void); static char *hostname(void); -static char *ip(const char *); +static char *ip(const char *iface); static char *load_avg(void); static char *ram_free(void); static char *ram_perc(void); static char *ram_used(void); static char *ram_total(void); -static char *run_command(const char *); -static char *temp(const char *); +static char *run_command(const char *cmd); +static char *temp(const char *file); static char *uid(void); static char *uptime(void); static char *username(void); -static char *vol_perc(const char *); -static char *wifi_perc(const char *); -static char *wifi_essid(const char *); -static void set_status(const char *); -static void sighandler(const int); +static char *vol_perc(const char *card); +static char *wifi_perc(const char *iface); +static char *wifi_essid(const char *iface); +static void set_status(const char *str); +static void sighandler(const int signo); static void usage(void); char *argv0; -- 2.20.1 From dd0f0cd30e6055201cc979497facc60dc60af215 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 17:51:25 +0200 Subject: [PATCH 06/16] README.md reloaded --- CONTRIBUTING.md | 2 ++ README.md | 35 +++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 46baccf..1da8c0b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,3 +2,5 @@ Contributing ============ If you want to contribute, please use [the suckless coding style](http://suckless.org/coding_style). + +Feel free to add yourself to [CONTRIBUTORS.md](CONTRIBUTORS.md) afterwards if you want. diff --git a/README.md b/README.md index 686922c..7bb3dc3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ ![slstatus](slstatus.png) -**slstatus** is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM). It is written in pure C without any system calls and only reads from files most of the time. It is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated for this use). +**slstatus** is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM) or any other status bars if they support reading/piping from slstatus. It is written in pure C without any extern programs being executed and only reads from files most of the time. slstatus is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated and written in C++). -If you write a bash script that shows system information in WM_NAME, it executes a huge amount of external commands (top, free etc.) every few seconds. This results in high system resource usage. slstatus solves this problem by only using C libraries and/or reading from files in sysfs/procfs. +If you write a bash script that shows system information in WM_NAME (or any other status bar), it executes a huge amount of external commands (top, free etc.) every few seconds. This results in high system resource usage. slstatus solves this problem by only using C libraries and/or reading from files in sysfs/procfs most of the time. -Looking at the LOC (lines of code) of the [Conky project](https://github.com/brndnmtthws/conky), very interesting: *28.346 lines C++, 219 lines Python and 110 lines Lua*. slstatus currently has about **800 lines of clean documented C code** and even includes additional possibilities as it can be customized and extended very easily. Configure it by customizing the config.h (C header file) which is secure and fast as no config files are parsed at runtime. +Looking at the LOC (lines of code) of the [Conky project](https://github.com/brndnmtthws/conky), it is very interesting: *28346 lines C++, 219 lines Python and 110 lines Lua*. slstatus currently has about **800 lines of clean documented C code** and even includes additional possibilities as it can be customized and extended very easily. Configuring it by customizing the config.h (C header) file is very secure and fast as no config files are parsed at runtime. The following information is included: @@ -14,40 +14,47 @@ The following information is included: - Date and time - Disk[s] status (free storage, percentage, total storage and used storage) - Available entropy -- username/gid/uid +- Username/GID/UID - Hostname - IP addresses -- Load average +- Load averages - Memory status (free memory, percentage, total memory and used memory) - Temperature - Uptime -- Volume percentage + mute status (alsa) -- WiFi signal percentage and essid +- Volume percentage (ALSA) +- WiFi signal percentage and ESSID -Multiple entries per function are supported and everything can be reordered and customized via the C header file config.h (similar to DWM). +Multiple entries per function (e.g. multiple batteries) are supported and everything can be reordered and customized via a C header file (similar to other suckless programs). ## Usage ### Installation -Before you continue, please be sure that a C compiler (preferrably gcc), GNU make and `alsa-lib` (for volume percentage) are installed. Then copy config.def.h to config.h and customize it to fit your needs. Recompile and install it after modifications: +Be sure you satisfy the dependencies: X11 and optionally ALSA (for volume percentage, I will *not* support PulseAudio). +Also you should have basic development tools like a C compiler and GNU make installed. +Then copy config.def.h to config.h and customize it to your needs. +(Re)Compile (and install) it (after modifications): $ make clean all # make install ### Starting -Write the following code to your ~/.xinitrc (or any other initialization script): +If you use DWM or any other window manager that uses WM_NAME, write the following code to ~/.xinitrc (or any other initialization script) to start slstatus automatically: - slstatus & + slstatus -d + +If you use any other status bar or window manager you will have to figure it out yourself. Something like this could fit your requirements: + + slstatus -o | other_status_bar & ## Contributing -In [TODO.md](TODO.md) there is a list of things that have to be done. +Hunt FIXME's in the code or do WTF you want! If it is useful, I will merge. -People who contributed are listed in [CONTRIBUTORS.md](CONTRIBUTORS.md). +People who contributed are listed in [CONTRIBUTORS.md](CONTRIBUTORS.md). Please add yourself to this list afterwards. -For detailed information about coding style and restrictions see [CONTRIBUTING.md](CONTRIBUTING.md) +For detailed information about coding style and restrictions see [CONTRIBUTING.md](CONTRIBUTING.md). ## License -- 2.20.1 From 915eeb8b49c7209368820609ae40f63d53c3c4e8 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 21:06:28 +0200 Subject: [PATCH 07/16] lol, dwm != slstatus in manpage :D --- slstatus.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slstatus.1 b/slstatus.1 index adaf052..5cfaf94 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -2,7 +2,7 @@ .SH NAME slstatus \- suckless status .SH SYNOPSIS -.B dwm +.B slstatus .RB [ \-dho ] .SH DESCRIPTION slstatus is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM). It is written in pure C without any system calls and only reads from files most of the time. It is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated for this use). -- 2.20.1 From fad39093cc1e2abf737d29082e87a5f503866de3 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 21:07:02 +0200 Subject: [PATCH 08/16] added -v to manpage --- slstatus.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slstatus.1 b/slstatus.1 index 5cfaf94..6de6f6a 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -3,7 +3,7 @@ slstatus \- suckless status .SH SYNOPSIS .B slstatus -.RB [ \-dho ] +.RB [ \-dhov ] .SH DESCRIPTION slstatus is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM). It is written in pure C without any system calls and only reads from files most of the time. It is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated for this use). .SH OPTIONS -- 2.20.1 From fd36f65cc7bd3c506ec57ac8af0c905187952e52 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 21:08:21 +0200 Subject: [PATCH 09/16] updated man page according to readme --- slstatus.1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slstatus.1 b/slstatus.1 index 6de6f6a..9234b18 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -5,7 +5,7 @@ slstatus \- suckless status .B slstatus .RB [ \-dhov ] .SH DESCRIPTION -slstatus is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM). It is written in pure C without any system calls and only reads from files most of the time. It is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated for this use). +slstatus is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM) or any other status bars if they support reading/piping from slstatus. It is written in pure C without any extern programs being executed and only reads from files most of the time. slstatus is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated and written in C++). .SH OPTIONS .TP .B \-d -- 2.20.1 From f4a383382cdd4a1aba1bb3f731e14ba85e6d0b4a Mon Sep 17 00:00:00 2001 From: "Ali H. Fardan" Date: Sun, 18 Sep 2016 22:27:04 +0300 Subject: [PATCH 10/16] several changes --- config.mk | 5 ----- slstatus.1 | 6 +++--- slstatus.c | 17 +++++++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config.mk b/config.mk index 75463df..12415a0 100644 --- a/config.mk +++ b/config.mk @@ -1,7 +1,3 @@ -# See LICENSE file for copyright and license details. - -VERSION = 2.0 - PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man @@ -11,7 +7,6 @@ X11LIB = /usr/X11R6/lib INCS = -I. -I/usr/include -I${X11INC} LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound -CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE # -Wno-unused-function for routines not activated by user CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} diff --git a/slstatus.1 b/slstatus.1 index 9234b18..aaeb42d 100644 --- a/slstatus.1 +++ b/slstatus.1 @@ -5,14 +5,14 @@ slstatus \- suckless status .B slstatus .RB [ \-dhov ] .SH DESCRIPTION -slstatus is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM) or any other status bars if they support reading/piping from slstatus. It is written in pure C without any extern programs being executed and only reads from files most of the time. slstatus is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated and written in C++). +slstatus is a suckless and lightweight status monitor for window managers that use WM_NAME as statusbar (e.g. DWM) or any other status bars as long as they support reading from stdin. It is written in pure C without any extern programs being executed and only reads from files most of the time. slstatus is meant to be a better alternative to Bash scripts (inefficient) and Conky (bloated and written in C++). .SH OPTIONS .TP .B \-d -runs slstatus as daemon in background +run slstatus as daemon in background .TP .B \-h -displays usage +display help .TP .B \-o output to console instead of WM_NAME diff --git a/slstatus.c b/slstatus.c index 49b14de..34fd951 100644 --- a/slstatus.c +++ b/slstatus.c @@ -1,4 +1,11 @@ -/* See LICENSE file for copyright and license details. */ +/* + * Copyright (C) 2016, drkhsh + * Copyright (C) 2016, Ali H. Fardan (Raiz) + * see LICENSE for copyright details + */ + +#define _GNU_SOURCE +#define VERSION "2.0" #include #include @@ -88,10 +95,8 @@ smprintf(const char *fmt, ...) va_end(ap); ret = malloc(++len); - if (ret == NULL) { - warn("Malloc failed."); - return "n/a"; - } + if (ret == NULL) + err(1, "malloc"); va_start(ap, fmt); vsnprintf(ret, len, fmt, ap); @@ -613,7 +618,7 @@ main(int argc, char *argv[]) oflag = 1; break; case 'v': - printf("%s version %s (c) 2016 slstatus engineers\n", argv0, VERSION); + printf("slstatus %s (C) 2016 slstatus engineers\n", VERSION); return 0; default: usage(); -- 2.20.1 From bad8dc682dc81018a7f95080b5720cc467c17a6f Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 22:00:50 +0200 Subject: [PATCH 11/16] shorter copyright notice and moved back VERSION and _GNU_SOURCE as the man page version number fails --- config.mk | 5 +++++ slstatus.c | 9 +-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/config.mk b/config.mk index 12415a0..75463df 100644 --- a/config.mk +++ b/config.mk @@ -1,3 +1,7 @@ +# See LICENSE file for copyright and license details. + +VERSION = 2.0 + PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man @@ -7,6 +11,7 @@ X11LIB = /usr/X11R6/lib INCS = -I. -I/usr/include -I${X11INC} LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lasound +CPPFLAGS = -DVERSION=\"${VERSION}\" -D_GNU_SOURCE # -Wno-unused-function for routines not activated by user CFLAGS = -std=c99 -pedantic -Wno-unused-function -Wall -Wextra -Os ${INCS} ${CPPFLAGS} LDFLAGS = ${LIBS} diff --git a/slstatus.c b/slstatus.c index 34fd951..fd27570 100644 --- a/slstatus.c +++ b/slstatus.c @@ -1,11 +1,4 @@ -/* - * Copyright (C) 2016, drkhsh - * Copyright (C) 2016, Ali H. Fardan (Raiz) - * see LICENSE for copyright details - */ - -#define _GNU_SOURCE -#define VERSION "2.0" +/* See LICENSE file for copyright and license details. */ #include #include -- 2.20.1 From c5ace949e42d5c32584c66b4757ac30bf23729ff Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Sun, 18 Sep 2016 22:01:44 +0200 Subject: [PATCH 12/16] braces for one line statements in smprintf() --- slstatus.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slstatus.c b/slstatus.c index fd27570..f6e8339 100644 --- a/slstatus.c +++ b/slstatus.c @@ -88,8 +88,9 @@ smprintf(const char *fmt, ...) va_end(ap); ret = malloc(++len); - if (ret == NULL) + if (ret == NULL) { err(1, "malloc"); + } va_start(ap, fmt); vsnprintf(ret, len, fmt, ap); -- 2.20.1 From a2d2e801a2641c8747b4ef64cd88c706980ad5e3 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Mon, 19 Sep 2016 11:17:51 +0200 Subject: [PATCH 13/16] 3.0 --- config.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mk b/config.mk index 75463df..c120e76 100644 --- a/config.mk +++ b/config.mk @@ -1,6 +1,6 @@ # See LICENSE file for copyright and license details. -VERSION = 2.0 +VERSION = 3.0 PREFIX = /usr/local MANPREFIX = ${PREFIX}/share/man -- 2.20.1 From 3a3a3e410164d9740c9dd7003a01e26048af9087 Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Wed, 5 Oct 2016 11:40:36 +0200 Subject: [PATCH 14/16] better default config.h --- config.def.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index 4f56eb0..853adb6 100644 --- a/config.def.h +++ b/config.def.h @@ -33,8 +33,8 @@ - wifi_perc (wifi signal in percent) [argument: wifi card interface name] - wifi_essid (wifi essid) [argument: wifi card interface name] */ static const struct arg args[] = { - /* function format argument */ - { cpu_perc, "[ CPU %4s ]", NULL }, - { ram_perc, "[ Mem %3s ]", NULL }, - { datetime, "[ %s ]", "%F %T" }, + /* function format argument */ + { cpu_perc, "[CPU %4s] ", NULL }, + { ram_perc, "[RAM %3s] ", NULL }, + { datetime, "[ %s ]", "%F %T" }, }; -- 2.20.1 From 6239e5de17cd1e008f5dfc532d4549642217101c Mon Sep 17 00:00:00 2001 From: Aaron Marcher Date: Wed, 5 Oct 2016 22:56:25 +0200 Subject: [PATCH 15/16] added name to LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index b77b557..5056ffa 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ ISC License -Copyright (C) 2016, drkhsh +Copyright (C) 2016 Aaron Marcher Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice -- 2.20.1 From fb440d8f622142c11e98e4799b7adceb33cd23b0 Mon Sep 17 00:00:00 2001 From: user Date: Sat, 8 Oct 2016 19:50:53 +0300 Subject: [PATCH 16/16] vol_perc: return zero if the value of max is set to zero --- slstatus.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/slstatus.c b/slstatus.c index f6e8339..ba7f95a 100644 --- a/slstatus.c +++ b/slstatus.c @@ -501,7 +501,10 @@ vol_perc(const char *card) snd_mixer_selem_id_free(s_elem); snd_mixer_close(handle); - return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); + if (max == 0) + return smprintf("%d%%", 0); + else + return smprintf("%d%%", ((uint_fast16_t)(vol * 100) / max)); } static char * -- 2.20.1