[Feature] Add support for wildcards in path_exists
- Dominant language
- C
- Stars
- 653
- Forks
- 254
- PR merge metrics
- No merged PRs in 30d
Description
Network manager now uses XFRM interfaces for VPN connections. These interfaces have randomized names like nm-xfrm-1234. Hence the example given in i3status doc with `path_exists /proc/.../tun0` no longer works. To detect that an xfrm interface is UP one needs to resolve `/proc/sys/net/ipv4/conf/nm-xfrm-*` but path_exists doesn't seem to care for wildcards. There is an ugly workaround that consists in running a demon script whose only job would be to resolve the wildcard and write the result into a file with a fixed name. Wouldn't it be much cleaner to add support for wildcards ? Glob is already a dependency of the project and a path with no patterns adds no extra work or system calls as opposed to running separate scripts outside of i3status.
I'm not a seasoned contributor of i3, so not offering a proper PR, but it would be something along the lines of:
```
diff --git a/src/print_path_exists.c b/src/print_path_exists.c
index 054f12e..bb6c4a5 100644
--- a/src/print_path_exists.c
+++ b/src/print_path```_exists.c
@@ -6,6 +6,7 @@
#include
#include
-#include
+#include
#include "i3status.h"
#define STRING_SIZE 5
@@ -13,8 +14,9 @@
void print_path_exists(path_exists_ctx_t *ctx) {
const char *walk;
char *outwalk = ctx->buf;
- struct stat st;
- const bool exists = (stat(ctx->path, &st) == 0);
+ glob_t glbuf;
+ const bool exists = (glob(ctx->path, 0, NULL, &glbuf) == 0);
+ globfree(&glbuf);
if (exists || ctx->format_down == NULL) {
walk = ctx->format;
```
Contributor guide
Assessment
This issue has not been assessed yet.