aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Mykyta Holubakha <hilobakho@gmail.com>2018-01-19 20:35:49 +0200
committerGravatar Mykyta Holubakha <hilobakho@gmail.com>2018-01-19 20:35:49 +0200
commit8a90aa7db7e63182f35a8acdf06c3e78ed6d5dde (patch)
treecc45ba59516dd7c16e07bb27ba9d5203b35c0eeb
parent2593ade60949909685c36d539b8bcd3f89c1943e (diff)
Allow to specify device name as a wildcard
-rw-r--r--README.md2
-rw-r--r--brightnessctl.c7
2 files changed, 5 insertions, 4 deletions
diff --git a/README.md b/README.md
index 7b81757..fc51389 100644
--- a/README.md
+++ b/README.md
@@ -34,7 +34,7 @@ Options:
-s, --save save previous state in a temporary file.
-r, --restore restore previous saved state.
-h, --help print this help.
- -d, --device=DEVICE specify device name.
+ -d, --device=DEVICE specify device name (can be a wildcard).
-c, --class=CLASS specify device class.
-V, --version print version and exit.
diff --git a/brightnessctl.c b/brightnessctl.c
index 71321c4..4cfaf29 100644
--- a/brightnessctl.c
+++ b/brightnessctl.c
@@ -4,6 +4,7 @@
#include <dirent.h>
#include <unistd.h>
#include <errno.h>
+#include <fnmatch.h>
#include <limits.h>
#include <getopt.h>
#include <stdio.h>
@@ -193,7 +194,7 @@ int main(int argc, char **argv) {
}
if (p.save)
if (save_device_data(dev))
- fprintf(stderr, "Could not save data for device '%s'.\n", dev_name);
+ fprintf(stderr, "Could not save data for device '%s'.\n", dev->id);
if (p.restore) {
if (restore_device_data(dev))
write_device(dev);
@@ -266,7 +267,7 @@ int parse_value(struct value *val, char *str) {
struct device *find_device(struct device **devs, char *name) {
struct device *dev;
while ((dev = *(devs++)))
- if (!strcmp(dev->id, name))
+ if (!fnmatch(name, dev->id, 0))
return dev;
return NULL;
}
@@ -552,7 +553,7 @@ Options:\n\
-s, --save\t\t\tsave previous state in a temporary file.\n\
-r, --restore\t\t\trestore previous saved state.\n\
-h, --help\t\t\tprint this help.\n\
- -d, --device=DEVICE\t\tspecify device name.\n\
+ -d, --device=DEVICE\t\tspecify device name (can be a wildcard).\n\
-c, --class=CLASS\t\tspecify device class.\n\
-V, --version\t\t\tprint version and exit.\n\
\n\